question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESM build does not work in the browser ("debug")

See original GitHub issue

Describe 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:

  1. 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>
  1. Use a dev server that resolved bare imports, for example @web/dev-server: npx web-dev-server --node-resolve --open
  2. Visit the HTML page
  3. 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
LarsDenBakkercommented, Sep 21, 2021

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.

1reaction
LarsDenBakkercommented, Sep 16, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found