【问题标题】:`npm install` Returns an errors`npm install` 返回错误
【发布时间】:2017-10-04 03:05:31
【问题描述】:

我一步一步做了Angular的指南: https://angular.io/guide/quickstart

当我到达npm install的步骤时

我收到此错误:

morwin@morwin-PC MINGW64 ~/Documents/angular2
$ npm install

> angular2@1.0.0 postinstall C:\Users\morwin\Documents\angular2
> typings install

typings ERR! message Unable to connect to "https://api.typings.org/entries/dt/node/tags/4.0.0%2B20160509154515"
typings ERR! caused by unable to verify the first certificate

typings ERR! cwd C:\Users\morwin\Documents\angular2
typings ERR! system Windows_NT 6.1.7601
typings ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\morwin\\Documents\\angular2\\node_modules\\typings\\dist\\bin.js" "install"
typings ERR! node -v v6.1.0
typings ERR! typings -v 0.8.1
typings ERR! code EUNAVAILABLE

typings ERR! If you need help, you may report this error at:
typings ERR!   <https://github.com/typings/typings/issues>

npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.12
npm WARN angular2@1.0.0 No description
npm WARN angular2@1.0.0 No repository field.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v6.1.0
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! angular2@1.0.0 postinstall: `typings install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular2@1.0.0 postinstall script 'typings install'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     typings install
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs angular2
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls angular2
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\morwin\Documents\angular2\npm-debug.log

所以我尝试继续npm start

我得到:

morwin@morwin-PC MINGW64 ~/Documents/angular2
$ npm start

> angular2@1.0.0 start C:\Users\morwin\Documents\angular2
> tsc && concurrently "npm run tsc:w" "npm run lite"

node_modules/@angular/core/src/application_ref.d.ts(39,88): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(99,42): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(174,33): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(24,15): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(26,16): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/di/reflective_provider.d.ts(105,123): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/di/reflective_provider.d.ts(105,165): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/async.d.ts(27,33): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/async.d.ts(28,45): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/collection.d.ts(1,25): error TS2304: Cannot find name 'MapConstructor'.
node_modules/@angular/core/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'SetConstructor'.
node_modules/@angular/core/src/facade/collection.d.ts(4,27): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/collection.d.ts(4,39): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/collection.d.ts(7,9): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/collection.d.ts(8,30): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/collection.d.ts(11,43): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/collection.d.ts(12,27): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/collection.d.ts(14,23): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/collection.d.ts(15,25): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/collection.d.ts(100,41): error TS2304: Cannot find name 'Set'.
node_modules/@angular/core/src/facade/collection.d.ts(101,22): error TS2304: Cannot find name 'Set'.
node_modules/@angular/core/src/facade/collection.d.ts(102,25): error TS2304: Cannot find name 'Set'.
node_modules/@angular/core/src/facade/lang.d.ts(4,17): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/lang.d.ts(5,17): error TS2304: Cannot find name 'Set'.
node_modules/@angular/core/src/facade/lang.d.ts(70,59): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/promise.d.ts(2,14): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/promise.d.ts(8,32): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/promise.d.ts(9,38): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/promise.d.ts(10,35): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/promise.d.ts(10,93): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/promise.d.ts(11,34): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/promise.d.ts(11,50): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/promise.d.ts(12,32): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/promise.d.ts(12,149): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/promise.d.ts(13,43): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/linker/component_resolver.d.ts(8,53): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/linker/component_resolver.d.ts(12,44): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/linker/dynamic_component_loader.d.ts(62,148): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/linker/dynamic_component_loader.d.ts(103,144): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/linker/dynamic_component_loader.d.ts(108,139): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/linker/dynamic_component_loader.d.ts(109,135): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/reflection/reflector.d.ts(28,22): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/reflection/reflector.d.ts(30,15): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/reflection/reflector.d.ts(32,15): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/reflection/reflector.d.ts(34,15): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/reflection/reflector.d.ts(36,16): error TS2304: Cannot find name 'Set'.
node_modules/@angular/core/src/testability/testability.d.ts(40,20): error TS2304: Cannot find name 'Map'.
node_modules/@angular/platform-browser-dynamic/platform_browser_dynamic.d.ts(75,90): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(10,66): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(66,60): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(66,70): error TS2304: Cannot find name 'Promise'.

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.1.0
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! angular2@1.0.0 start: `tsc && concurrently "npm run tsc:w" "npm run lite" `
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the angular2@1.0.0 start script 'tsc && concurrently "npm run tsc:w" "npm run lite" '.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     tsc && concurrently "npm run tsc:w" "npm run lite"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs angular2
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls angular2
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\morwin\Documents\angular2\npm-debug.log

我应该怎么做才能让它工作?

【问题讨论】:

标签: node.js npm angular typescript-typings


【解决方案1】:

第一个错误“由无法验证第一个证书引起”。 它看起来像一个打字代理问题。创建一个名为 .typingsrc 的文件并将其放在您的主目录中。

.typingsrc:

{
    "proxy": "http://<proxyURI>:<port>",
    "rejectUnauthorized": false
}

第二个错误“找不到名称'Promise'。” (等等)

在您的 tsconfig.json 文件中,在“compilerOptions”下生成“target”:“es6”

"compilerOptions": {
    "outDir": "app",
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true
}

【讨论】:

  • 我应该填写什么 ?我不认为我在代理上,因为我检查了我的路由器 ip(在 10.0.0.138 ..)和 whatismyip.com,它是相同的 ip 地址
  • 如果您不在代理后面,请删除该行。
  • 我只有第二个问题(“找不到名称'Promise'。”(等等))并将目标从“es5”更改为“es6”修复了它。我想知道为什么AngularJs教程提供了“es5”的目标呢?
  • @jdebon:他们可能正在更新。
  • @Moti Winkler:typings.json 中的 globalDependencies 是静态的。在执行 'typings install' 之前尝试更新依赖项,执行 'npm run typings -- install dt~node --save --global'
【解决方案2】:

在你的用户目录中创建一个文件名.typingsrc

C:\Users\morwin - 例如

包含:

{
     "rejectUnauthorized": false,
     "registryURL": "http://api.typings.org/"
}

就是这样

现在可以使用了!

【讨论】:

  • 这对我不起作用,但我确实可以使用这个 package.json:
  • 这里的配置对我有用:link
【解决方案3】:

也许你没有正确复制所有文件,最简单的克隆github的项目,像这样:

git clone ./my-angular-app https://github.com/angular/quickstart

是一个最完整、最有帮助的例子。

【讨论】:

  • 你得到同样的错误?,你是否已经在全球范围内安装了 TypeScrip 编译器?
  • 我做了 Angular 的指南。我应该安装哪个编译器?
  • 首先你需要安装typescript编译器,你可以这样安装:npm install -g typescript,link,
  • 我安装了它。和npm Intall 返回:gist.github.com/morwin10/2a5dade1867d09797ff559ceb4cb8c12
  • 我认为我找到了问题所在。 documentation 说您需要 node 5.x.x 和 npm 3.x.x 版本才能使用它,其他版本可能会产生错误...我安装了 4.x.x lts,但我没有'没有任何问题有点奇怪。
猜你喜欢
  • 2023-03-16
  • 2020-02-27
  • 1970-01-01
  • 2018-01-21
  • 2021-11-30
  • 2016-10-28
  • 2018-02-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多