How to make packages that depend on msw/browser work in nextjs. #2452
nayounsang
started this conversation in
Show and tell
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Abstract
msw/browser(likesetupWorker) in nextjs project directly, It's difficult to get packages withmsw/browserdependencies to work well in next.problem situation
my-packagedependency.my-packagehasmswfor peer dependency. And it usessetupWorkerfrommsw/browser.my-packageimportmsw/browserdynamically in browser env.my-packagein nextjs, It cannot resolvemsw/browserfrommy-package. Why?!Why
exportproperty in package.json.msw/browserdoes not export anything in node(server) env.use clientdirective is only works for files directly within Nextjs. I believe it doesn't recognize theuse clientdirective within node_module or external workspace files. Therefore, using your package with use client is not enough.use clientinterprets it to work in the browser.).msw/browserinmy-package. The build system want to resolve it in node(server) env. Because it located innode_modulesor somewhere in the monorepo workspace.How to fix it
msw/browseronly from browser withtypeof windowand dynamic import. standard example in msw docsmsw/browserin build process! It still works fine in runtime since build proccess just not analyzing it.Beta Was this translation helpful? Give feedback.
All reactions