-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
Vitest tests fail with error "Cannot find package 'graphql' imported" in v2.4.0 #2248
Comments
We ran into the same thing here #2247 |
I have the same issue here. Installing the graphql package |
Also happens to us with jest:
|
@kettanaito |
@kettanaito |
Merged the peer dependency fix, opened the lazy import fix in #2250. Reviews are welcome. If someone can also try that PR build in their project, please comment if it fixes the issue or not. |
Released: v2.4.1 🎉This has been released in v2.4.1! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Not work for me. |
If it doesn't work for you, please share a reproduction repo below. |
The issue persists with
EDIT: I am using webpack. |
@jsphstls, reproduction repo, please. That looks like an error originating from the |
webpack runs in to this too -- I think webpack is incorrect here, because it tries to resolve everything, and doesn't understand that some modules deliberately might not be available |
@kettanaito, here's a reproduction repo with next.js. All I did was create-next-app and then installed msw. https://github.com/nareshbhatia/msw-issue If we run $ npm run build
> [email protected] build
> next build
▲ Next.js 14.2.7
Creating an optimized production build ...
Failed to compile.
./node_modules/msw/lib/core/utils/internal/parseGraphQLRequest.mjs
Module not found: Can't resolve 'graphql'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/msw/lib/core/handlers/GraphQLHandler.mjs
./node_modules/msw/lib/core/index.mjs
./src/mocks/handlers.js
./src/mocks/browser.js
./src/providers/useMockServiceWorker.ts
./src/providers/AppProvider.tsx
> Build failed because of webpack errors |
@nareshbhatia, thanks! Can you try the latest MSW version please? |
Hi @kettanaito, tried with msw 2.4.2. Still have the same issue. |
I suspect this is webpack's magic behavior in regards to dynamic imports. It looks like webpack treats them as a splitting point by default, trying to generate a chunk for There are different webpack modes to treat dynamic imports. It looks like we need to set
|
Opened a fix at #2265. Can confirm this fixes the Next.js/webpack builds as reported in #2248 (comment). Went with using the |
Released: v2.4.3 🎉This has been released in v2.4.3! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Thank you, @kettanaito. It works now. |
I'm reopening this because the solution hasn't been found yet. This expects GraphQL to be a static import, while the current issue needs it as a dynamic import. Neither work with optional dependencies, and then you add tools like webpack on top that handle dynamic imports in a custom way altogether. Optional peer dependencies is a mess in JavaScript, and I'm open to suggestions at this point. |
Prerequisites
Environment check
msw
versionNode.js version
v20.10.0
Reproduction repository
https://github.com/am-ma/msw2.4.0-examples-for-issue/tree/main/examples/with-vitest
Reproduction steps
Current behavior
All tests fail.
FAIL example-jsdom.test.ts [ example-jsdom.test.ts ] FAIL example.test.ts [ example.test.ts ] Error: Cannot find package 'graphql' imported from {userDir}/msw2.4.0-examples-for-issue/examples/with-vitest/node_modules/msw/lib/core/utils/internal/parseGraphQLRequest.mjs
Expected behavior
Tests succeed without error.
The text was updated successfully, but these errors were encountered: