Angular学习笔记88:Angular12中使用crypto-js运行提示Warning

Angular12更新到webpack5.42.0后,使用crypto-js出现警告。在项目配置中添加相应代码可消除警告,不影响运行。
摘要由CSDN通过智能技术生成

在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"
   ]
}

重新运行一下就可以了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值