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.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:20
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
kettanaitocommented, May 25, 2022

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.

3reactions
kettanaitocommented, May 30, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Critical dependency: require function is used in a way in which ...
Critical dependency : require function is used in a way in which dependencies cannot be statically extracted · Subscribe to RSS.
Read more >
Incompatible with Webpack - Google Groups
"require function is used in a way, in which dependencies cannot be statically extracted" These errors come when trying to "require" specific modules, ......
Read more >
Critical dependency: require function is ... - Auth0 Community
Error message : Critical dependency: require function is used in a way in which dependencies cannot be statically extracted.
Read more >
Node.js – WARNING in Critical dependency: require function ...
Node.js – WARNING in Critical dependency: require function is used in a way in which dependencies cannot be statically extracted. angularnode.jswebpack.
Read more >
Linting error with Moralis react - Largest Web3 Dev Community
Critical dependency : require function is used in a way in which dependencies cannot be statically extracted.
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