【问题标题】:How to fix "module not found error" in xhr2-cookies如何修复 xhr2-cookies 中的“模块未找到错误”
【发布时间】:2019-10-06 13:09:50
【问题描述】:

我的代码是使用 angular CLI 7.3.1 编写的,当我尝试使用 ng build 构建时,出现以下错误

ERROR in ./node_modules/xhr2-cookies/dist/xml-http-request.js
Module not found: Error: Can't resolve 'http' in '/home/User/Desktop/fy_project_blockchain/angularSwarm/node_modules/xhr2-cookies/dist'
ERROR in ./node_modules/xhr2-cookies/dist/xml-http-request.js
Module not found: Error: Can't resolve 'https' in '/home/User/Desktop/fy_project_blockchain/angularSwarm/node_modules/xhr2-cookies/dist'

我已尝试删除 xhr2-cookies 并重新安装它。我也尝试安装http https模块,在xml-http-request.js文件中给出模块的路径,但它仍然给我同样的错误。任何帮助将不胜感激。

【问题讨论】:

    标签: angular http https xmlhttprequest angular-cli


    【解决方案1】:

    将此添加到您的 package.json 文件中

      "browser": {
        "http": false,
        "https": false,
        "os": false
      }
    

    【讨论】:

      【解决方案2】:

      import * as Cookie from 'cookiejar'; XMLHttpRequest.cookieJar = Cookie.CookieJar();

      像上面一样使用

      【讨论】:

      • 感谢您的快速回复。试过了,还是一样的错误
      • 你在哪里导入cookiejar?
      • 在 xhr2-cookies 的 dist 文件夹内的 xml-http-request.js 文件中
      猜你喜欢
      • 2021-09-04
      • 2021-04-08
      • 2020-10-04
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-04
      相关资源
      最近更新 更多