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
Cannot find module msw/node after updating #1960
Comments
Hi, @joshbenhamou. I've just updated all the examples to the latest version of MSW and they all pass. Could you please confirm your issue is solved? |
Thanks @kettanaito . The sandbox link is no longer working for me in https://github.com/mswjs/examples/tree/main/examples/with-vitest. However, I saw that you updated the MSW package to 2.0.14 and tried that locally. Same problem with that version and also with 2.1.3 |
Oh, thanks for pointing out the broken sandboxes! Caused by renaming the repo and deleting the old one. Will fix. Edit: the sandbox is running properly now but it doesn't seem CodeSandbox allows us to use terminal anymore to run tests. You may want to check that example locally. |
Thanks. The sandbox is working for me now. It looks like the change you've made that is the |
I'm experiencing the same issue, but no changes to module/moduleResolution seem to resolve it in my project. I do notice that the sandbox is a major version behind on both vitest and resolved vite version.. that being said, after bumping these, I still cannot reproduce the issue in the sandbox 🙃 |
Same as @iChip , it's still not working for me but I haven't had the time to investigate yet unfortunately |
Same thing happens for me. My setup is Remix, Cloudflare Workers, Playwright with following configs: ...
"moduleResolution": "Bundler",
"module": "ES2022",
"resolveJsonModule": true,
"target": "ES2022",
... /** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: [`**/.*`],
server: `./app/server.ts`,
serverConditions: ['workerd', 'worker', 'browser'],
serverDependenciesToBundle: [
// bundle everything except the virtual module for the static content manifest provided by wrangler
/^(?!.*\b__STATIC_CONTENT_MANIFEST\b).*$/,
],
serverMainFields: [`browser`, `module`, `main`],
serverMinify: true,
serverModuleFormat: `esm`,
serverPlatform: `neutral`,
browserNodeBuiltinsPolyfill: {
modules: {
buffer: true,
},
},
serverNodeBuiltinsPolyfill: {
modules: ['util', 'crypto'],
},
} Do we have any ideas what might be the cause? I am willing to give a stab and fixing it if there is a person who could point me to a direction! |
Just want to chime and and mention I am upgrading MSW from 1.3.3 to 2.2.13 and receive the same error Package path ./node is not exported from package /Users/damien/Documents/Git/Maia/monorepo/node_modules/msw (see exports field in /Users/damien/Documents/Git/Maia/monorepo/node_modules/msw/package.json) My scripts is very basic import { setupServer, type SetupServer } from 'msw/node';
import { handlers } from './handlers';
export const server: SetupServer = setupServer(...handlers); |
I'm also running into the same issue after upgrading. My use case is to mock out API responses for components using Storybook and the MSW addon. I tried upgrading everything together -- MSW to v2, msw-storybook-addon to v2, Storybook from v7 to v8 -- but no matter what I try I'm getting the same error as @DamienDeloubes. I tried the hacky solution mentioned in another issue but that still caused errors with any component's Storybook file that was using the MSW addon. I've tried adjusting my |
IDK if this will help you, but I had a similar issue and found that the hacky solution only worked if I removed the |
Thanks for the idea. Unfortunately, I'm still getting the |
With the help from @phryneas, we've done some improvements in the export conditions in MSW. Please upgrade to |
Hmm, I still seem to encounter the same error when pinning the msw package to 2.3.0.
|
I am also still receiving the same error when trying to run/build Storybook (which uses MSW pretty heavily). |
You will still need to ensure that you have a |
Thanks for your input! What do you mean exactly? For example, I am working in a NextJS repository with MSW used for mocking endpoints. The setup looks fairly straightforward, this has always worked for us: import { setupServer, type SetupServer } from 'msw/node';
import { handlers } from './handlers';
export const server: SetupServer = setupServer(...handlers); However, I am still encountering the build issue as described above. How would I go about resolving that issue? |
Are you using vitest? import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
resolve: {
// this line is important so the "browser build" of dependencies is used
// and not the "SSR build", which would contain "streaming-to-the-browser"
// specific code
// "node" is important so it picks up the right msw import.
conditions: ["browser", "node"],
},
test: {
globals: true,
environment: "jsdom",
},
}); |
Unfortunately not vite, just a plain NextJS project |
So you are trying to mock the network access inside of React Server Components? I'm not sure if that's supported. Also, afaik Next.js simulates their edge runtime in some cases - not sure if you can mock anything in that environment. |
Sorry, I see I was a bit unclear. I have a NextJS project where I use Redux Toolkit Query. For the past year, I have used MSW to make the requests made by RTQ. Unfortunately when I upgraded the MSW package I got the error described in this thread, moving back to an older version fixes everything. So I don't want to mock server components, just the rtq apis. |
So, still pages router. Maybe @kettanaito knows something on how to set that up - you'll need some additional bundler config. |
Prerequisites
Environment check
msw
versionNode.js version
21.4.0
Reproduction repository
https://github.com/mswjs/examples/tree/main/examples/with-vitest
Reproduction steps
The issue is happening in the official MSW Vitest example. Check out the sandbox link and see the typescript error https://codesandbox.io/p/sandbox/github/mswjs/examples-new/tree/main/examples/with-vitest?file=%2Fmocks%2Fnode.ts%3A2%2C32-3%2C1
Current behavior
Import validation fails
Expected behavior
Import validation succeeds
The text was updated successfully, but these errors were encountered: