【发布时间】:2021-06-26 11:21:12
【问题描述】:
在开发 web/node.js 应用程序方面,我是一个初学者(如果我解释得不够好,请见谅),现在我正在研究一个角度和角度材料项目。我认为这不是重点...
我的应用程序是用 typescript 编写的 - 但是我使用的是编译为 javascript 的 typescript 库。该库使用“网络请求”。到目前为止,我只使用该库中的一个文件(但该文件使用同一库中的其他文件),我将通过 import { MyClass } from '../../lib/file_1' 和 myclass = new MyClass(); 将其命名为“file_1.js”。
file_1.d.ts 和 file_1.js.map 也存在,我只能假设它们已正确实施。事实上,我已经从我之前工作过的一个 react 项目中复制粘贴了这个库,它在那里工作得很好。
file_1.js 仅在两种情况下使用此库:因此具有:
const WebRequest = require("web-request");
let response = yield WebRequest.get(openUri, requestOptions);
let response = yield WebRequest.post(postUri, requestOptions, jsonBody);
我非常有信心图书馆本身是健全的。当尝试通过 ng serve 运行我的服务器时,我遇到了很多问题,即 web-request 的依赖关系没有得到解决:
Error: ./node_modules/aws-sign2/index.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/aws-sign2'
Error: ./node_modules/aws4/aws4.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/aws4'
Error: ./node_modules/ecc-jsbn/index.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/ecc-jsbn'
Error: ./node_modules/http-signature/lib/signer.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/http-signature/lib'
Error: ./node_modules/http-signature/lib/verify.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/http-signature/lib'
Error: ./node_modules/oauth-sign/index.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/oauth-sign'
Error: ./node_modules/request/lib/oauth.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/request/lib'
Error: ./node_modules/request/lib/helpers.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/request/lib'
Error: ./node_modules/request/lib/hawk.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/request/lib'
Error: ./node_modules/sshpk/lib/identity.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/sshpk/lib'
Error: ./node_modules/sshpk/lib/fingerprint.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/sshpk/lib'
Error: ./node_modules/sshpk/lib/utils.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/sshpk/lib'
Error: ./node_modules/sshpk/lib/signature.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/sshpk/lib'
Error: ./node_modules/sshpk/lib/private-key.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/sshpk/lib'
Error: ./node_modules/sshpk/lib/certificate.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/sshpk/lib'
Error: ./node_modules/sshpk/lib/key.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/sshpk/lib'
Error: ./node_modules/sshpk/lib/dhe.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/sshpk/lib'
Error: ./node_modules/sshpk/lib/formats/pem.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/sshpk/lib/formats'
Error: ./node_modules/sshpk/lib/formats/ssh-private.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/sshpk/lib/formats'
Error: ./node_modules/sshpk/lib/formats/openssh-cert.js
Module not found: Error: Can't resolve 'crypto' in '/home/ubuntu/my_website/node_modules/sshpk/lib/formats'
Error: ./node_modules/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in '/home/ubuntu/my_website/node_modules/request/lib'
Error: ./node_modules/request/request.js
Module not found: Error: Can't resolve 'zlib' in '/home/ubuntu/my_website/node_modules/request'
我尝试在此处应用 snorberhuis 建议的解决方案:Angular 6 many Can't resolve errors (crypto, fs, http, https, net, path, stream, tls, zlib),将其添加到我的 package.json:
"browser": {
"http": false,
"https":false,
"net": false,
"path": false,
"stream": false,
"tls": false,
"crypto": false,
"fs": false,
"zlib": false
}
服务器启动时没有问题 - 但浏览器窗口仍然是空白,控制台中出现错误:
【问题讨论】:
标签: javascript angular typescript rest