ng serve找不到node.js核心模块

时间:2019-02-27 21:29:15

标签: angular angular7

我跑步时

ng serve --watch

我收到这些构建错误:

Module not found: Error: Can't resolve 'http' in '/home/oleg/codes/oresoftware/fb-wars/node_modules/forever-agent'
ERROR in ./node_modules/http-signature/lib/signer.js
Module not found: Error: Can't resolve 'http' in '/home/oleg/codes/oresoftware/fb-wars/node_modules/http-signature/lib'
ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'http' in '/home/oleg/codes/oresoftware/fb-wars/node_modules/request'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'http' in '/home/oleg/codes/oresoftware/fb-wars/node_modules/tunnel-agent'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'https' in '/home/oleg/codes/oresoftware/fb-wars/node_modules/forever-agent'
ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'https' in '/home/oleg/codes/oresoftware/fb-wars/node_modules/request'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'https' in '/home/oleg/codes/oresoftware/fb-wars/node_modules/tunnel-agent'

所有错误都与无法找到node.js核心模块定义有关,这似乎很奇怪,特别是考虑到我安装了节点类型:

{
  "name": "fb-wars",
  "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/animations": "~7.1.0",
    "@angular/common": "~7.1.0",
    "@angular/compiler": "~7.1.0",
    "@angular/core": "~7.1.0",
    "@angular/forms": "~7.1.0",
    "@angular/platform-browser": "~7.1.0",
    "@angular/platform-browser-dynamic": "~7.1.0",
    "@angular/router": "~7.1.0",
    "core-js": "^2.5.4",
    "fb": "^2.0.0",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.11.0",
    "@angular/cli": "~7.1.2",
    "@angular/compiler-cli": "~7.1.0",
    "@angular/language-service": "~7.1.0",
    "@types/fb": "0.0.23",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^11.9.5",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.6"
  }
}

有人知道会发生什么吗?

ng --version的意思是:

   _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.1.4
Node: 11.3.0
OS: linux x64
Angular: 7.1.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.4
@angular-devkit/build-angular     0.11.4
@angular-devkit/build-optimizer   0.11.4
@angular-devkit/build-webpack     0.11.4
@angular-devkit/core              7.1.4
@angular-devkit/schematics        7.1.4
@ngtools/webpack                  7.1.4
@schematics/angular               7.1.4
@schematics/update                0.11.4
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.23.1

1 个答案:

答案 0 :(得分:0)

看起来像是因为我安装了Facebook软件包“ fb”,其中使用了一些核心的node.js模块。我想在浏览器中使用该程序包,不确定是否会运行,但是要忽略浏览器版本中的那些模块,可以将其放在package.json中:

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

是的,行不通的,显然需要安装与NPM上名为“ fb”的JS sdk不同的JS sdk,目前正试图找出安装方法:

https://developers.facebook.com/docs/javascript/quickstart