【问题标题】:Failed at the @angular/cli@8.3.19 postinstall script@angular/cli@8.3.19 安装后脚本失败
【发布时间】:2022-04-30 11:16:19
【问题描述】:

您好,我无法使用 npm install -g @angular/cli@8.3.19 安装 angular cli。 我不断得到这个:

> node ./bin/postinstall/script.js

module.js:549
    throw err;
    ^

Error: Cannot find module '/root/.nvm/versions/node/v13.0.1/lib/node_modules/@angular/cli/bin/postinstall/script.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @angular/cli@8.3.19 postinstall: `node ./bin/postinstall/script.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @angular/cli@8.3.19 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-11-26T00_10_33_515Z-debug.log

节点版本:13.0.1
Npm 版本:6.13.1
Ubuntu 版本:18.04.2

我也尝试过不指定 CLI 版本。

【问题讨论】:

    标签: node.js angular npm


    【解决方案1】:

    我尝试使用我在网上找到的这个命令:

    npm install -g @angular/cli@8.3 --unsafe-perm=true --allow-root
    

    它奏效了。

    【讨论】:

      【解决方案2】:

      尝试使用sudo npm 运行。在 Ubuntu 上,您需要以 root 权限运行。这取决于您如何安装节点。

      sudo npm install -g @angular/cli@8.3.19
      

      另一方面,尝试安装 node 12 和 LTS 版本以获得更安全的版本。

      希望对你有帮助

      【讨论】:

      • /usr/local/bin/node: 1: /usr/local/bin/node: ELF: not found /usr/local/bin/node: 12: /usr/local/bin/node: Syntax error: word unexpected (expecting ")")
      • 尝试卸载node 13并安装node版本12,因为node版本13不稳定。
      【解决方案3】:

      尝试在 npm cache cleannpm cache verify 之前清理你的 npm 缓存,然后是 npm install -g @angular/cli@8.3 --unsafe-perm=true --allow-root

      【讨论】:

        【解决方案4】:

        我遵循的步骤

        1. 使用 nvm 将节点版本降级到 v12.3.0
        2. /root/.nvm/versions/node/v12.3.0/bin 中删除ng 文件夹
        3. 再做npm install -g @angular/cli@8.3 --unsafe-perm=true --allow-root

        成功了

        【讨论】:

          猜你喜欢
          • 2019-12-22
          • 1970-01-01
          • 2017-02-14
          • 1970-01-01
          • 1970-01-01
          • 2017-08-02
          • 2015-02-11
          • 2016-10-21
          • 1970-01-01
          相关资源
          最近更新 更多