在Angular的12版本中,使用了webpack的5.42.0版本,在这种情况下,使用crypto-js会出现如下提示信息,虽然不影响项目运行,在开发过程中会很难受。
./node_modules/crypto-js/core.js:43:22-39 - Warning: Module not found: Error: Can't resolve 'crypto' in '/Users/wjy/WebstormProjects/ng12/devops-web-ng12/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 }
解决方案:
在tsconfig.json
文件中的compilerOptions
中,添加如下:
"paths": {
"crypto": [
"node_modules/crypto-js"
]
}
重新运行一下就可以了。