next example not using 'require'
See original GitHub issueIs your feature request related to a problem? Please describe. We are using next js w/ msw. In the example posted here: https://github.com/vercel/next.js/blob/canary/examples/with-msw/pages/_app.js#L1
a require()
is done which adds msw to the bundle. We are using a lot of big json files for fixture data in conjunction w/ our msw endoints. And the use of require here is causing our bundle size to balloon.
Describe the solution you’d like Looking for a way to safely load msw before any react renders that doesn’t use require.
Describe alternatives you’ve considered await import() but that seems to cause race conditions where msw doesn’t load in time (i.e. before react tries to fetch)
Additional context Add any other context or screenshots about the feature request here.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
@kettanaito There seems to have been a regression in the next.js build process as now msw is being included in the bundle. I’ve opened an issue for it with next.js here: https://github.com/vercel/next.js/issues/25607 (note that I tested this by removing .env.production from the example, as otherwise you would expect msw to be present in the bundle, since
NEXT_PUBLIC_API_MOCKING
would beenabled
). See the linked issue for more details.I confirm that the Official NextJS usage example does not include
msw
package in its production bundle. See the bundle analyzer screenshot below.with-msw
state as of https://github.com/vercel/next.js/commit/746000ea5e55c12763defe01028d03ae765eda67 commitmsw@0.20.x
If you have a custom build setup make sure you are importing
msw
conditionally so it doesn’t end up in the production bundle unused. If you want to runmsw
in production intentionally it must be included by design in order to run.