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

I’m getting this warning in the console: ./node_modules/@0x/utils/node_modules/ethers/dist/ethers.min.js Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

I’m importing into my files the following:

import { Contract } from '@ethersproject/contracts';
import { Web3Provider } from '@ethersproject/providers';

I’m using Next.js.

Any idea as to why I’m getting this error?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (2 by maintainers)

Most upvoted comments

I’m getting the exact same error: ./node_modules/ethers/dist/ethers.min.js Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

while ethers is correctly installed in my project root package json.

I’m also using Next.js.

The issue has something to do with Web3Provider. I had somehow fixed it, but unfortunately, I do not remember anymore.

Can you give a code snippet of how you are importing ethers in your project?

Do you have ethers directly installed in your project root package json? Seems that webpack module resolution is picking up @ethersproject/contracts from 0x dependencies instead.