【问题标题】:npm install: Failed at the node-sass@3.13.1 postinstall scriptnpm install:在 node-sass@3.13.1 安装后脚本失败
【发布时间】:2019-06-22 23:07:42
【问题描述】:

我有一个 Angular 应用程序:https://github.com/XBITSwitzerland/ngx-admin/tree/ng2-admin

现在我尝试做:npm install

但是我得到了这个错误(命令的竞争输出太长了,所以我只分享最后一部分):

gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\github\ngx-admin\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\github\\ngx-admin\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\github\ngx-admin\node_modules\wintersmith-sassy\node_modules\node-sass
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
Build failed with error code: 1
npm WARN ngx-toastr@4.4.1 requires a peer of @angular/core@^2.2.0 but none is installed. You must install peer dependencies yourself.
npm WARN ngx-toastr@4.4.1 requires a peer of @angular/common@^2.2.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\webpack-dev-server\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 WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\watchpack\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 WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@3.13.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@3.13.1 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!     C:\Users\danyb\AppData\Roaming\npm-cache\_logs\2019-01-29T18_25_12_699Z-debug.log

有人知道为什么会出现这个错误以及如何解决它吗?

【问题讨论】:

  • 如果您需要完全安装 3.13.1,您需要将 Node.JS 降级到 v7 或更低

标签: node.js angular npm npm-install node-sass


【解决方案1】:

我认为这是因为您缺少 node-sass 模块。尝试以下操作并重新运行您的构建脚本,看看是否能解决您的问题:

npm install node-sass@latest

另外,我看到您在 Windows 平台上使用 fsevents,只是警告此模块仅支持对 OS X FSEvents 的本机访问

【讨论】:

    【解决方案2】:

    如果您遇到此问题,请阅读此页面:https://www.bramvandenbulcke.be/en/kb/failed-node-sass3131-postinstall-script

    我的解决方案:

    1) 删除package-lock.json文件

    2)npm install gulp-sass --save-dev

    3)npm install node-sass@latest

    版本具体说明:

    node-sass@3.13.1 仅在Node.js 最高版本上运行,如release notes 所述:

    【讨论】:

    • 我只尝试删除 package-lock.json 文件并运行 npm install 到我想要的任何包,它对我有用。
    【解决方案3】:

    在这条消息之后,我在 npm install 上遇到了错误 node-sass@3.13.1 postinstall: node scripts/build.js

    > node scripts/install.js
    
    Downloading binary from https://github.com/sass/node-sass/releases/download/v3.13.1/linux-x64-72_binding.node
    Cannot download "https://github.com/sass/node-sass/releases/download/v3.13.1/linux-x64-72_binding.node": 
    
    HTTP error 404 Not Found
    
    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
    
    > core-js@2.6.9 postinstall /var/www/my/armat/www/node_modules/core-js
    > node scripts/postinstall || echo "ignore"
    

    并花费数小时寻找解决方案。我试图将它安装在使用旧版本节点和 npm 的 laravel 5.2 上,这对我有帮助

    $ npm install -g n
    $ n 6.10.2    // selecting version you need in my case 6.10.2
    $ npm install -g npm@3.10.10 // same for npm
    

    希望这对其他人有帮助^_^

    #######UPDATE###########

    nvm install 6.10.2
    nvm use 6.10.2
    npm install -g npm@3.10.10
    

    【讨论】:

    • 这对我来说是同样的问题。使用 nvm 从 v12 降级到 v10。
    【解决方案4】:

    我也收到了同样的错误

    "npm ERR! 代码 ELIFECYCLE npm 错误!错误号 1 npm 错误! node-sass@3.13.1 安装后:node scripts/build.js npm 错误!退出状态 1 npm 错误! npm 错误!在 node-sass@3.13.1 安装后脚本失败。 npm 错误!这可能不是 npm 的问题。上面可能还有额外的日志输出。”

    解决方案:

    我在 package.json 文件中将 node-sass 和 gulp-sass 版本增加到最新,然后问题得到修复。

    【讨论】:

      【解决方案5】:

      只删除

      package-lock.json

      文件

      再做一次npm install

      【讨论】:

      • 不,这行不通。需要安装 Gulp sass 以消除该特定错误。
      【解决方案6】:

      对我来说,问题在于 Linux 目录权限。即使使用 sudo 和 root 用户,我也无法使其工作。

      我的解决方案是按如下方式更改项目目录所有者:

      sudo chown my_user:my_user -R /path/to/project 
      

      【讨论】:

        【解决方案7】:

        分别执行以下命令:

        rm -rf package-lock.json
        
        npm install node-sass@latest
        

        【讨论】:

          【解决方案8】:

          如果您在错误输出中进一步向上滚动并看到类似以下内容:

          gyp verb check python checking for Python executable "python2" in the PATH
          gyp verb `which` failed Error: not found: python2
          

          您可以通过以下步骤在 Windows 上修复它:

          1. 删除node_modules文件夹
          2. 以管理员身份运行npm install --global windows-build-toolsin powershell
          3. npm install重新安装节点模块或节点sass

          【讨论】:

            【解决方案9】:

            对于 Ubuntu

            1. 删除 package-lock.json 文件

            2. sudo npm install gulp-sass --save-dev

            3. sudo npm install node-sass@latest

            【讨论】:

              【解决方案10】:

              如果你使用 Visual Studio 运行以下命令:

              npm cache clean --force
               npm config set msvs_version 2019 --global
              

              其中 2019 是 Visual Studio 的版本

              【讨论】:

                【解决方案11】:

                如果您使用的是 OpenBSD,那是因为您需要 g++。使用安装它

                pkg_add g++
                

                但是,它作为 ec++ 安装在 /usr/local/bin 上,因此您可以复制、重命名或创建符号链接 使用:

                ln -s /usr/local/bin/ec++ /usr/local/bin/g++
                

                再次执行npm install,它应该可以工作了

                【讨论】:

                  猜你喜欢
                  • 2018-06-26
                  • 2021-10-14
                  • 2018-10-16
                  • 2020-01-25
                  • 2018-11-06
                  • 2020-02-25
                  • 2018-11-23
                  • 2019-05-17
                  • 1970-01-01
                  相关资源
                  最近更新 更多