ESM build does not work in the browser ("debug")
See original GitHub issueDescribe the bug
The es module build ships bare module imports, which can be resolved using a dev server or other tool. But when using the es module build in the browser it fails because it’s importing the “debug” module which is actually a commonjs module.
Environment
msw: 0.35.0
nodejs: 16.4.0
npm: 7.18.0
Please also provide your browser version.
To Reproduce
Steps to reproduce the behavior:
- Create a simple HTML page that imports MSW:
<!DOCTYPE html>
<html>
<head></head>
<body>
<script type="module">
import * as mswjs from 'msw';
console.log(mswjs);
</script>
</body>
</html>
- Use a dev server that resolved bare imports, for example
@web/dev-server
:npx web-dev-server --node-resolve --open
- Visit the HTML page
- See this error:
Uncaught SyntaxError: The requested module './../../../debug/src/index.js' does not provide an export named 'default'
Expected behavior
MSW imports a browser compatible module.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:13 (7 by maintainers)
Top Results From Across the Web
milahu/debug-esm
A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers. Installation. This ...
Read more >Debugging ES Modules in Node.js and Mocha Using VS Code
Integrate in-editor debugging, unit tests, and JavaScript's new module system seamlessly with this simple trick.
Read more >javascript - How to inspect ES6 modules in chrome debugger
I know Chrome breakpoints on sourcemaps don't work brilliantly if the generated scripts are minified. Even when they're not it's hit and miss ......
Read more >Troubleshooting
Vite cannot handle and does not support code that only runs on non-strict mode (sloppy mode). This is because Vite uses ESM and...
Read more >[CRITICAL] Can't debug Node.js with `--experimental- ...
This doesn't look like a problem with Node, but with WebStorm, because, ... (node:32240) ExperimentalWarning: The ESM module loader is experimental.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Since debug is only a small module, I recommend bundling it into the esm build of MSW. Or to create a separate output with all dependencies bundled.
@patrickmcdougle-okta @kettanaito unfortunately that’s not the case. Even if debug is there in the node_modules, the module itself doesn’t work in the browser because it uses commonjs syntax not es module. So adding it as a dependency won’t solve it.