簡體   English   中英

“web-request” package 的依賴關系問題。 無法解析 'stream'、'tls'、'zlib'、'path'、'net'、'https'、'http'、'fs'、'crypto'

[英]Issues with dependencies of “web-request” package. Can't resolve 'stream', 'tls', 'zlib', 'path', 'net', 'https', 'http', 'fs', 'crypto'

在開發 web/node.js 應用程序方面,我是初學者(如果我對自己的解釋不夠好,請道歉),現在我正在研究 angular 和 angular 材料項目。 然而我認為這不是重點……

我的應用程序是用 typescript 編寫的 - 但是我使用的是編譯為 javascript 的 typescript 庫。 該庫使用“網絡請求”。 到目前為止,我只使用該庫中的一個文件(但該文件使用同一庫中的其他文件),我將通過import { MyClass } from '../../lib/file_1'myclass = new MyClass(); .

file_1.d.tsfile_1.js.map存在,我只能假設它們已正確實施。 事實上,我已經從我不久前從事的一個反應項目中復制粘貼了這個庫,它在那里工作得很好。

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'

I tried applying the solution suggested by snorberhuis here: Angular 6 many Can't resolve errors (crypto, fs, http, https, net, path, stream, tls, zlib) by adding this to my package.json:

  "browser": {
    "http": false,
    "https":false,
    "net": false,
    "path": false,
    "stream": false,
    "tls": false,
    "crypto": false,
    "fs": false,
    "zlib": false
  }

然后服務器啟動沒有問題 - 但瀏覽器 window 仍然是空白,控制台中出現錯誤:

在此處輸入圖像描述

問題是“web-request”模塊不是為了在瀏覽器中工作,而是在節點服務器上工作。 您需要使用不同的 package 來實現您需要的目標。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM