msw: webpack 5: Failed to parse source map from "@mswjs/interceptors"
Describe the bug
New webpack 5.0 throwing compilation error regarding source map not found
there are multiple of these, but for the sake of simplicity, i just pasted one of it.
Environment
msw: 0.36.3
nodejs: 14.18.2
npm: 8.3.0
Please also provide your browser version. N/A, this is compilation warning error
To Reproduce
Steps to reproduce the behavior:
- Create new react app using CRA5.0
- install latest msw.
- Npm start, the warnings are being thrown in the terminal
Expected behavior
should not have these warning errors.
Screenshots
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 28
- Comments: 17 (6 by maintainers)
Commits related to this issue
- Disable source-map generation for mswjs - Fixes warnings: [Failed to parse source map from](https://github.com/mswjs/msw/issues/1070) - https://github.com/mswjs/msw/issues/1030 — committed to akunzai/react-boilerplate by akunzai 2 years ago
- fix: msw issues on yarn start Issue and fix described here: https://github.com/mswjs/msw/issues/1030#issuecomment-1004245791 — committed to neldeles/slash-clone by neldeles 2 years ago
- chore(webpack): prevent source map generation This is a known issue in the Interceptor project of MSW. See workaround here: https://github.com/mswjs/msw/issues/1030#issuecomment-1009253387 — committed to zoom-care/schedule-app by sclarkson-zoomcare 2 years ago
- DoubleScrollbar.js.mapがENOENTであると表示されないように設定 ref: https://github.com/mswjs/msw/issues/1030#issuecomment-1004245791 — committed to TetsuOtter/web-mon by TetsuOtter 2 years ago
- webpack 5: Failed to parse source map from... webpack 5: Failed to parse source map from "@mswjs/interceptors" Modeled after: https://github.com/mswjs/msw/issues/1030 https://github.com/mswjs/inter... — committed to avipatel97/capacitor-firebase-auth by avipatel97 2 years ago
- webpack 5: Failed to parse source map from... (#31) webpack 5: Failed to parse source map from "@mswjs/interceptors" Modeled after: https://github.com/mswjs/msw/issues/1030 https://github.com/mswjs... — committed to jay-babu/capacitor-firebase-auth by avipatel97 2 years ago
- chore+feat: Install and configure Rainbowkit NOTE! Source maps generated in Webpack under react-scripts are busted. https://github.com/mswjs/msw/issues/1030 GENERATE_SOURCEMAP=false — committed to davidvuong/pozition by davidvuong 2 years ago
For Windows Users 🚀🤘
Create an environment variables file named
.env
in the project root and addGENERATE_SOURCEMAP=false
to it.OR
Run
npm i -D cross-env
and then in thepackage.json
file update the start script to the following:In case someone is lost on how to do it, just add the
GENERATE_SOURCEMAP=false
before the start script. In my case:Hello,
The source map files links to the src/ - folder that is not distributed.
In the source-map-loader README it says: “The source-map-loader will extract from any JavaScript file, including those in the node_modules directory.”.
As for CRA 5: I think a change was added in this PR: https://github.com/facebook/create-react-app/pull/8227 Commit: https://github.com/facebook/create-react-app/commit/382ba21052ffd1321f3e7bb1dcb70d442106dff1#diff-8e25c4f6f592c1fcfc38f0d43d62cbd68399f44f494c1b60f0cf9ccd7344d697 Current source: https://github.com/facebook/create-react-app/blob/9673858a3715287c40aef9e800c431c7d45c05a2/packages/react-scripts/config/webpack.config.js#L350
I’m seeing these warnings when starting the dev server using
react-scripts start
, If i exclude the above config by settingGENERATE_SOURCEMAP=false
when starting the dev server the warnings disappear.I have a suspicion that CRA5 should configure webpack to ignore source maps from
node_modules
. I’d like to know how it used to behave previously.Meanwhile, source-map-loader can be configured to exclude @mswjs like this (keeping current excludes used in CRA5):
Not sure if this is related, as my problem isn’t about source maps but polyfill breaking changes with webpack 5.
CRA 5 msw 0.36.8
🎉 This issue has been resolved in version 0.38.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
@kettanaito
You were, of course, entirely correct in your diagnosis. Followed your suggested directory structure and all sorted. Thanks for the prompt response. Much appreciated!
I guess it’s just a matter of including ./src in https://github.com/mswjs/msw/blob/ddbc5a7ce30eabc56390eba79e0d260f3a8f598d/package.json#L44.
Hey, @JoeyAtSS. Thanks for reporting this.
It looks like the issue is coming from the sourcemaps for the
@mswjs/interceptors
package:I don’t think this is an issue with the library itself, as we haven’t changed our bundling process in a while. It may be an indirect issue of webpack5 behaving differently, to which we have to find a proper way to adjust.
One thing I’m not certain about is why webpack attempts to require modules from the sourcemaps. To my best knowledge, sourcemaps link the compiled and source code to ease your debugging whenever the former has any issues. I wouldn’t expect the source module references to be imported.