msw: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Prerequisites

Environment check

  • I’m using the latest msw version
  • I’m using Node.js version 14 or higher

Node.js version

v16.15.0

Reproduction repository

https://github.com/akunzai/react-boilerplate

Reproduction steps

yarn add msw@0.41.0
CI=true yarn build

Current behavior

The CI pipeline failed with warnings: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Creating an optimized production build...

Treating warnings as errors because process.env.CI = true.
Most CI servers set it automatically.

Failed to compile.

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

and the warning was caused by ./node_modules/msw/lib/esm/index.js.

$ yarn start
Compiled with warnings.

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

WARNING in ./node_modules/msw/lib/esm/index.js 30:70-77
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

WARNING in ./node_modules/msw/lib/esm/index.js 33:45-52
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

webpack compiled with 2 warnings

Expected behavior

Run the CI pipeline successfully.

Creating an optimized production build...
Compiled successfully.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 24
  • Comments: 18 (10 by maintainers)

Most upvoted comments

Maybe the reason is that Webpack does not like UMD wrappers.

That’d be our fault if UMD slips through somehow. We’ve removed the UMD build target in 0.41.0.

The error originates from the esm target, which should not have any require statements. It’d be nice to explore that built module and see if it indeed has a require and see why so.

Released: v0.42.0 🎉

This has been released in v0.42.0!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

FWIW we publish react-data-grid as both cjs and esm and it’s been working well for us, maybe you can take inspiration from our rollup/package.json config: https://github.com/adazzle/react-data-grid/blob/main/rollup.config.js https://github.com/adazzle/react-data-grid/blob/76030e6ef8ae775f56a22179935b925955ea62d6/package.json#L12-L23

@nstepien, that seems to be related to #912. We don’t ship ESM right now but the overall debug as a dependency is still pending. You can skip lib check if that blocks you or revert to a previous version. I’d like to have this resolved but I need help in looking into this properly.

I’m using version 0.40 as suggested until then

Please wait for the next release. You can see that there’s a linked PR above and it fixes the issue. Thank you.

@baptistefkt use resolutions (yarn) or overrides (npm) to pin msw package to 0.40.x.