【问题标题】:Cannot install angular/cli with npm无法使用 npm 安装 angular/cli
【发布时间】:2023-03-28 19:44:01
【问题描述】:

我正在尝试安装 Angular cli。我安装了 npm 版本 5.6.0 和节点 v8.11.1。这是我在命令提示符(管理员)中所做的:

justine:~ justine$ sudo npm install -g @angular/cli
/Users/justine/.node_modules_global/bin/ng -> /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/bin/ng

> fsevents@1.1.3 install /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/fsevents
> node install

[fsevents] Success: "/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile

> node-sass@4.8.3 install /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/node-sass
> node scripts/install.js

Unable to save binary /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/node-sass/vendor/darwin-x64-57 : { Error: EACCES: permission denied, mkdir '/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/node-sass/vendor'
at Object.fs.mkdirSync (fs.js:885:18)
at sync (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/mkdirp/index.js:71:13)
at Function.sync (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/mkdirp/index.js:77:24)
at checkAndDownloadBinary (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:114:11)
at Object.<anonymous> (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:157:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path:     '/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/node-sass/vendor' }

> uglifyjs-webpack-plugin@0.4.6 postinstall /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/webpack/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js


> node-sass@4.8.3 postinstall /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/node-sass
> node scripts/build.js

Building: /usr/local/bin/node /Users/justine/.node_modules_global/lib/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 [ '/usr/local/bin/node',
gyp verb cli   '/Users/justine/.node_modules_global/lib/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.6.2
gyp info using node@8.11.1 | darwin | 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 (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:89:16
gyp verb `which` failed     at /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:152:21)
gyp verb `which` failed  python2 { Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:89:16
gyp verb `which` failed     at /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:152:21)
gyp verb `which` failed   stack: 'Error: not found: python2\n    at getNotFoundError (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:13:12)\n    at F (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:68:19)\n    at E (/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:80:29)\n    at /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/which/which.js:89:16\n    at /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/isexe/index.js:42:5\n    at /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/isexe/mode.js:8:5\n    at FSReqWrap.oncomplete (fs.js:152:21)',
gyp verb `which` failed   code: 'ENOENT' }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python /usr/bin/python
gyp verb check python version `/usr/bin/python -c "import platform; print(platform.python_version());"` returned: "2.7.10\n"
gyp verb get node dir no --target version specified, falling back to host node version: 8.11.1
gyp verb command install [ '8.11.1' ]
gyp verb install input version string "8.11.1"
gyp verb install installing version: 8.11.1
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 8.11.1
gyp verb build dir attempting to create "build" dir: /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/node-sass/build
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/node-sass/build'
gyp ERR! System Darwin 16.7.0
gyp ERR! command "/usr/local/bin/node" "/Users/justine/.node_modules_global/lib/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 /Users/justine/.node_modules_global/lib/node_modules/@angular/cli/node_modules/node-sass
gyp ERR! node -v v8.11.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
Build failed with error code: 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: node-sass@4.8.3 (node_modules/@angular/cli/node_modules/node-sass):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: node-sass@4.8.3 postinstall: `node scripts/build.js`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ @angular/cli@1.7.4
added 993 packages in 34.312s

让您知道我的尝试:

  • 我已经卸载并删除了 angular/cli 并运行npm cache verify
  • 尝试使用 npm 版本 5.7.0 进行安装

不确定接下来要尝试什么。你能帮忙吗?

【问题讨论】:

    标签: angular npm-install


    【解决方案1】:

    我有同样的问题。我解决了这个问题: sudo npm install -g --unsafe-perm angular-cli

    【讨论】:

      【解决方案2】:

      如果您将 nodenpm 版本升级到最新版本会更好。之后请按照以下步骤安装 angular/cli:

      1. 使用管理权限打开命令提示符并使用 npm uninstall -g angular-cli 命令卸载 angular/cli
      2. 删除 node_modules 目录,然后使用 npm cache clear --force 命令清除缓存。
      3. 删除 C:\Users\\AppData\Roaming\npm\ 和 C:\Users\\AppData\Roaming\npm-cache。 4.尝试使用npm install -g @angular/cli@latest命令安装angular/cli@latest

      希望以上技巧能解决您的问题。

      【讨论】:

      • 感谢您的帮助。我在 macbook 上,你能确认我应该删除哪些文件夹吗?再次感谢
      • @JustineVer,请参考link,您可能会找到解决方案。
      • 再次感谢,我按照您的第 1 步和第 2 步操作,然后按照您提到的链接的第一个解决方案中给出的所有步骤进行操作。看来它已安装 ng -v 表明 Angular 未定义。 (并且 ng new testApp 返回“您不能在 Angular CLI 项目中使用新命令。”错误)
      • 抱歉,'您不能在 Angular CLI 项目中使用新命令。'是由于我在 /users/name 中有一个 package.json 文件,将其删除,角度 cli 似乎正在工作。非常感谢您的帮助!!!
      【解决方案3】:

      使用 npm cache clean 清理缓存,卸载 angular-cli npm uninstall -g angular-cli 并使用 npm install -g @angular/cli 重新安装,或者尝试使用 npm install -g -f angular-cli 强制安装。

      【讨论】:

      • 感谢您的及时回复。我已经完成了您给出的每一个建议,我得到了相同的错误日志(顺便说一句:我需要执行 npm cache clean -f)。任何进一步的帮助将不胜感激。
      • 这似乎是您的 node/npm 的问题,而不是 Angular CLI 的问题。请浏览this页面。
      猜你喜欢
      • 2018-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-13
      • 2015-11-27
      • 2018-07-13
      • 2018-07-02
      • 1970-01-01
      相关资源
      最近更新 更多