crypto报错:“crypto“: require.resolve(“crypto-browser“)

韶硕
2023-12-01

报错详细

“Module not found: Error: Can’t resolve ‘crypto’ in ‘D:\Projects\webpack-basic\webpack-ie-test\node_modules\crypto-js’
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback ‘resolve.fallback: { “crypto”: require.resolve(“crypto-browserify”) }’
- install ‘crypto-browserify’
If you don’t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { “crypto”: false }”

方法一:

查看了这篇博文 crypto报错
方法是配置package.json

"dependencies": {
    ...
  },
  "browser": {
    "crypto": false
  }

但是配置之后还是报错,最后按照提示配置webpack.resolve模块

resolve: {
    fallback: {
      crypto: false
    },
  },
  mode: 'development'

就解决了。

 类似资料: