错误信息:
重大变更:webpack <5 默认情况下包括 node.js 核心模块的 polyfill,但现在不再如此。请确认您是否需要该模块并配置相应的 polyfill。
我正在通过谷歌搜索解决此问题,但遇到了很多困难。因此,我想与您分享以下解决方案:
首先,这种情况不仅限于加密,还可能涉及 http、https、os 等其他内容。
检查是否安装了该包(在这种情况下是 crypto-browserify 包),应该有一个名为 node_modules\crypto-browserify 的文件夹。
如果不存在,请执行以下命令:npm install crypto browsrify
,然后执行 yarn add @types/node@15.12.5 -D
(针对此 Node 版本)。
在 node_modules\crypto-browserify 中编辑 package.json 并添加:
,
"optionalDependencies": {},
"browser": {
"crypto": false
},
(在 devDependencies 之后)
- 在 tsconfig.json 下添加
"compilerOptions": {
"paths":{
"crypto":["node_modules/crypto-browserify"],
"http":["node_modules/stream-http"],
"https":["node_modules/https-browserify"]
},
- 在 angular.json 中添加
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"allowedCommonJsDependencies": ["crypto"],
"allowedCommonJsDependencies": ["http"],
"allowedCommonJsDependencies": ["https"],
json
来获得正确的语法高亮。 - Darren Cook