Ill*_*lep 2 javascript node.js npm angular nem
我在运行时收到以下错误列表ng serve。
我的包JSON如下:
{ "name": "ProName", "version": "0.0.0", "scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e" }, "private": true, "dependencies": {
"@angular-devkit/build-angular": "~0.12.0",
"@angular/animations": "5.2.10",
"@angular/common": "5.2.10",
"@angular/compiler": "5.2.10",
"@angular/compiler-cli": "5.2.10",
"@angular/core": "5.2.10",
"@angular/forms": "5.2.10",
"@angular/platform-browser": "5.2.10",
"@angular/platform-browser-dynamic": "5.2.10",
"@angular/router": "5.2.10",
"@types/dotenv": "^4.0.3",
"@types/errorhandler": "0.0.32",
"@types/express": "^4.16.0",
"@types/node": "^10.5.1",
"apostille-library": "^7.1.0",
"core-js": "^2.5.4",
"dotenv": "^6.0.0",
"errorhandler": "^1.5.0",
"express": "^4.16.0",
"nem2-sdk": "^0.9.7",
"rxjs": "~6.3.3",
"stream": "0.0.2",
"tslib": "^1.9.0",
"typescript": "^2.9.2",
"zone.js": "~0.8.26" } }
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
./node_modules/aws-sign2/index.js中的错误找不到模块:错误:无法解析“ / Users / MYPC / Documents / Myproj / ProName / node_modules / aws-sign2”中的“ crypto”。./node_modules中的错误/aws4/aws4.js找不到模块:错误:无法解析'/ Users / MYPC / Documents / Myproj / ProName / node_modules / aws4'中的'crypto'错误。/node_modules/ecc-jsbn/index.js模块中找不到:错误:无法在'/ Users / MYPC / Documents / Myproj / ProName / node_modules / ecc-jsbn'中解析'crypto'在./node_modules/http-signature/lib/verify.js中找不到错误模块:错误:无法在'/ Users / MYPC / Documents / Myproj / ProName / node_modules / http-signature / lib'中解析'crypto'在./node_modules/http-signature/lib/signer.js中的错误未找到模块:错误:无法解析“./node_modules/nem-sdk/build/external/nacl-fast.js中的/ Users / MYPC / Documents / Myproj / ProName / node_modules / http-signature / lib'错误找不到模块:错误:无法解析'crypto在'/ Users / MYPC / Documents / Myproj / ProName / node_modules / nem-sdk / build / external'中的错误在./node_modules/nem-sdk/node_modules/aws-sign2/index.js中
小智 35
在该项目下的tsconfig.ts文件中添加此设置可解决此警告
"compilerOptions": {
"baseUrl": "./",
"paths": {
"crypto": [
"../../node_modules/crypto-js"
]
}
Run Code Online (Sandbox Code Playgroud)
lem*_*ing 20
我想我会扩展塔里克·艾哈迈德 (Tarique Ahmed) 在他的回答中所写的内容。
我使用的 npm 模块在代码中包含以下行:
const crypto = require('crypto');
Run Code Online (Sandbox Code Playgroud)
我无法添加:
"browser": {
"crypto": false
}
Run Code Online (Sandbox Code Playgroud)
到 package.json 因为crypto包必须是构建的一部分。
事实证明,在编译过程中,Angular 似乎决定安装crypto-browserify包而不是crypto.
将以下内容添加到tsconfig.json文件中会指示构建在crypto-browserify每次crypto需要时使用该库。如您所见,我对stream包裹有同样的问题。
"paths": {
"crypto": [
"node_modules/crypto-browserify"
],
"stream": [
"node_modules/stream-browserify"
]
}
Run Code Online (Sandbox Code Playgroud)
Oll*_*rca 15
在 Angular 11 和 crypto-js 4 遇到同样的问题(并在 tsconfig.json 中手动设置路径)后,我发现将 crypto-js 回滚到版本 3.1.9-1 解决了这个问题。似乎在第 4 版中所做的更改导致了该问题。
npm install crypto-js@3.1.9-1
Run Code Online (Sandbox Code Playgroud)
在回购问题中解释如下:
最近,我在尝试使用的一个小项目中尝试使用另一个库(tiff.js)时遇到了类似的问题。
我解决此问题的方法是在本节之后立即将以下内容添加到我的package.json文件中devDependencies。
"devDependencies": {
...
},
"browser": {
"crypto": false
}
Run Code Online (Sandbox Code Playgroud)
尝试在应用程序中使用库时,这似乎没有任何不利影响。
如果您升级到 Webpack 5,则需要将其添加到您的webpack 配置文件中:
resolve: {
fallback: { crypto: false },
},
Run Code Online (Sandbox Code Playgroud)
我喜欢R. Richards的回答,但我认为提供更多信息会很有用。
这是Angular的一个已知问题,并且Angular CLI开发团队似乎认为这是功能而不是错误。我以及本主题中的其他开发人员均不同意。该线程的提供者提供了几种解决方法,但在实施R. Richards的解决方案之前,我的项目无法成功编译。不过,我没有还原以前的更改,因此tacnoman和GrandSchtroumpf的修复程序可能对其他人有用。
有些人(例如此处的clovis1122和该问题线程中的其他人)质疑为什么Web应用程序需要访问这些库,以及为什么不能在服务器端完成必要的任务。我不能代表所有人,但我的用例是,在对用户帐户进行身份验证时,Strapi将使用必须由客户端解码的JSON Web令牌字符串进行响应。由于必要的库取决于crypto和stream,除非这些依赖项可用,否则您将无法提取JWT到期时间。
如果有人无法从R. Richards的答案推断出问题,则必须将出现在“无法解析x”错误中的所有依赖项设置为false。例如,我的package.json的关键部分是:
"browser": {
"crypto": false,
"stream": false
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3838 次 |
| 最近记录: |