-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
instanceof checks fail when using peerDeps? #5601
Comments
This seems like yet-another instance of
Your source code is always transformed, so both were seeing Actually, I don't know why Vitest/Vite is not reading You can try |
Hi! Thanks for the quick response! I've tried using deps.inline and it does work for the repro I have created (adding 'test-package'). Though for our real project it ends up throwing this error at me: It seems like the |
Hmm, I expected Also the other thing I was wondering about is rather unusual |
One more thing I forgot to mention is that you can force Vitest's resolution using import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
export default defineConfig({
test: {
alias: {
// or maybe simply __dirname + "/node_modules/graphql/index.js"
"graphql": require.resolve("graphql"),
}
}
}); |
Ah, yes you're right. I forgot that there were other packages with a peer dependency on I can also confirm that the second solution work as well. We might prefer that for now since it seems like that's the package causing the issue. Thanks again 🙏 |
Describe the bug
Hi there!
First of all, thank you for all the hard work on vitest! Very much appreciated 🙏 !
When upgrading from 1.4.0 to 1.5.0. we are seeing some of our tests fail.
When debugging we noticed this seems to be related with a failing
instanceof
check.More specifically, we have an Apollo GraphQL server and we are relying on
instanceof
to verify whether an error is an instance of GraphQLError in some places. With 1.5.0error instanceof GraphQLError
fails whereas with 1.4.0 this succeeds.In this specific case the package @apollo/server is throwing the GraphQLError instance. Apollo server imports GraphQLError from the
graphql
package on which it has a peerDependency. Our own project then also specifies a dependency on thegraphql
packages and importsGraphQLError
to do the instanceof check.It feels like somehow the graphql package gets duplicated during bundling? This might explain why
instanceof
fails?To be clear we are not seeing this issue during runtime. Only when running tests with vitest.
Reproduction
I have tried to come up with a minimal reproduction:
github: https://github.com/skrivle/vitest-deps-repro.
stackblitz: https://stackblitz.com/~/github.com/skrivle/vitest-deps-repro
yarn test
to see failing unit testyarn start
to see a similar check with node succeed.I have created a test-package that has a peerDependency on
graphql
just as apollo/server does in our case. This package then throws aGraphQLError
. In app.spec.ts we are then verifying whether the error thrown is an instanceofGraphQLError
. This fails in the test. However when running a similar script with node (run yarn start) the check seems to succeed just fine.❗ In our graphql server project our tests do pass with 1.4.0 but fail with 1.5.0. However with the repro I've made, it seems to also be failing with 1.4.0. This is a bit suspicious. Though, I thought it might already be worth sharing...
System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: