如何修复xhr2-cookie中的“找不到模块错误”

时间:2019-05-20 07:38:20

标签: angular http https xmlhttprequest angular-cli

我使用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-cookie并重新安装。我也尝试安装http https模块,在xml-http-request.js文件中提供模块的路径,但仍然给我同样的错误。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

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

如上使用

答案 1 :(得分:0)

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

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