全局安装Angle CLI时出错

时间:2019-01-02 09:56:21

标签: node.js angular intellij-idea angular-cli

我是这个平台的新手。我正在使用IntelliJ Idea Ultimate Edition。我安装了节点js版本v10.14.2。

我尝试使用命令npm install -g @angular/cli收到以下错误。

npm ERR! path C:\Users\D\AppData\Roaming\npm\ng.cmd
npm ERR! code EEXIST
npm ERR! Refusing to delete C:\Users\D\AppData\Roaming\npm\ng.cmd: node_modules\angular-cli\bin\ng symlink target is not controlled by npm C:\Users\D\AppData\Roaming\npm\node_modules\@angular\cli
npm ERR! File exists: C:\Users\D\AppData\Roaming\npm\ng.cmd
npm ERR! Move it away, and try again.

我不确定在这里出什么问题。任何线索都会非常有帮助。

尝试安装后,出现以下错误

npm WARN deprecated angular-cli@1.0.0-beta.28.3: angular-cli has been renamed to @angular/cli. Please update your dependencies.
npm WARN deprecated exists-sync@0.0.3: Please replace with usage of fs.existsSync
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated boom@2.10.1: This version is no longer maintained. Please upgrade to the latest version.
npm WARN deprecated cryptiles@2.0.5: This version is no longer maintained. Please upgrade to the latest version.
npm WARN deprecated hoek@2.16.3: This version is no longer maintained. Please upgrade to the latest version.
npm WARN deprecated gulp-util@3.0.7: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
C:\Users\D\AppData\Roaming\npm\ng -> C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\bin\ng

> node-sass@4.11.0 install C:\Users\DRAJKUM3\AppData\Roaming\npm\node_modules\angular-cli\node_modules\node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.11.0/win32-x64-64_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.11.0/win32-x64-64_binding.node":

tunneling socket could not be established, cause=getaddrinfo ENOTFOUND f.com f.com:8080

Hint: If github.com is not accessible in your location
      try setting a proxy via HTTP_PROXY, e.g.

      export HTTP_PROXY=http://example.com:1234

or configure npm proxy via

      npm config set proxy http://example.com:8080

> node-sass@4.11.0 postinstall C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\node-sass
> node scripts/build.js

Building: C:\Program Files\nodejs\node.exe C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
gyp verb cli   'C:\\Users\\D\\AppData\\Roaming\\npm\\node_modules\\angular-cli\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library=' ]
gyp info using node-gyp@3.8.0
gyp info using node@10.14.2 | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
gyp verb `which` failed  python2 { Error: not found: python2
gyp verb `which` failed     at getNotFoundError (C:\Users\DRAJKUM3\AppData\Roaming\npm\node_modules\angular-cli\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
gyp verb `which` failed   stack:
gyp verb `which` failed    'Error: not found: python2\n    at getNotFoundError (C:\\Users\\D\\AppData\\Roaming\\npm\\node_modules\\angular-cli\\node_modules\\which\\which.js:13:12)\n    at F (C:\\Users\\DRAJKUM3\\AppData\\Roaming\\npm\\node_modules\\angular-cli\\node_modules\\which\\which.js:68:19)\n    at E (C:\\Users\\DRAJKUM3\\AppData\\Roaming\\npm\\node_modules\\angular-cli\\node_modules\\which\\which.js:80:29)\n    at C:\\Users\\DRAJKUM3\\AppData\\Roaming\\npm\\node_modules\\angular-cli\\node_modules\\which\\which.js:89:16\n    at C:\\Users\\DRAJKUM3\\AppData\\Roaming\\npm\\node_modules\\angular-cli\\node_modules\\isexe\\index.js:42:5\n    at C:\\Users\\DRAJKUM3\\AppData\\Roaming\\npm\\node_modules\\angular-cli\\node_modules\\isexe\\windows.js:36:5\n    at FSReqWrap.oncomplete (fs.js:154:21)',
gyp verb `which` failed   code: 'ENOENT' }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python C:\Users\D\AppData\Local\Programs\Python\Python37-32\python.EXE
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\D\AppData\Local\Programs\Python\Python37-32\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:962:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\D\\AppData\\Roaming\\npm\\node_modules\\angular-cli\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\Users\D\AppData\Roaming\npm\node_modules\angular-cli\node_modules\node-sass
gyp ERR! node -v v10.14.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN @angular/core@2.4.10 requires a peer of rxjs@^5.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\angular-cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.11.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.11.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我已经安装了PYTHON并将其设置为env变量。我也为GIT做过同样的事情。

EDIT2构建过程出错

The projects in this solution are created one after the other. To enable a parallel creation, you must add the "/ m" switch.
The build process was started on 02.01.2019 14:34:39.
Project "C: \ Users \ D \ IdeaProjects \ AngularHelloWorld \ helloworld \ node_modules \ node-sass \ build \ binding.sln" on node "1" (default destinations).
ValidateSolutionConfiguration:
The solution configuration "Release | x64" is created.
MSBUILD: error MSB3428: Could not load Visual C ++ component VCBuild.exe. To fix this problem, install either 1) the .NET Framework 2.0 SDK or 2) Microsoft Visual Studio 2005 or 3) add the location of the component m Add system path if it is different from the default location. [C: \ Users \ D \ Idea Projects \ AngularHelloWorld \ helloworld \ node_modules \ node-sass \ build \ binding.sln]
Creation of the project "C: \ Users \ D \ IdeaProjects \ AngularHelloWorld \ helloworld \ node_modules \ node-sass \ build \ binding.sln" is complete (default targets) - ERROR.


Error during the build process.

The projects in this solution are created one after the other. To enable a parallel creation, you must add the "/ m" switch.
The build process was started on 02.01.2019 14:34:39.
Project "C: \ Users \ D \ IdeaProjects \ AngularHelloWorld \ helloworld \ node_modules \ node-sass \ build \ binding.sln" on node "1" (default destinations).
ValidateSolutionConfiguration:
The solution configuration "Release | x64" is created.
MSBUILD: error MSB3428: Could not load Visual C ++ component VCBuild.exe. To fix this problem, install either 1) the .NET Framework 2.0 SDK or 2) Microsoft Visual Studio 2005 or 3) add the location of the component
m Add system path if it is different from the default location. [C: \ Users \ D \ Idea Projects \ AngularHelloWorld \ helloworld \ node_modules \ node-sass \ build \ binding.sln]
Creation of the project "C: \ Users \ D \ IdeaProjects \ AngularHelloWorld \ helloworld \ node_modules \ node-sass \ build \ binding.sln" is complete (default targets) - ERROR.

    Error during the build process.

    "C: \ Users \ D \ IdeaProjects \ AngularHelloWorld \ helloworld \ node_modules \ node-sass \ build \ binding.sln" (default destination) (1) ->
    (_src_ \ libsass destination) ->
      MSBUILD: error MSB3428: Could not load Visual C ++ component VCBuild.exe. To fix this problem, install either 1) .NET Framework 2.0 SDK or 2) Microsoft Visual Studio 2005 or 3) add the location of the component
    to the system path if it differs from the default location. [C: \ Users \ D \ Idea Projects \ AngularHelloWorld \ helloworld \ node_modules \ node-sass \ build \ binding.sln]

2 个答案:

答案 0 :(得分:1)

似乎您正在使用Python 3.x

...
Error: Command failed: C:\Users\D\AppData\Local\Programs\Python\Python37-32\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
...

node-gyp文档说支持Python 3.x https://github.com/nodejs/node-gyp

尝试完全卸载Python并安装v2.7

UPD:

您为什么甚至需要node-gyp如果您查看这些行

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.11.0/win32-x64-64_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.11.0/win32-x64-64_binding.node":

您会看到您的安装尝试为您的环境下载node-sass的预构建版本,但失败了。之后,程序将下载node-sass源并临时构建它们。此步骤需要安装node-gyp并准备使用。

答案 1 :(得分:0)

适用于Windows的步骤:

  1. 是否已通过命令正确安装了First Check Node JS最新版本
      

    node --version

然后按照以下步骤操作:

> npm uninstall -g @angular/cli
> npm cache clean
> npm install -g @angular/cli