【问题标题】:npm install with error: `gyp` failed with exit code: 1npm 安装错误:`gyp` 失败,退出代码:1
【发布时间】:2018-08-27 03:47:46
【问题描述】:

我正在尝试使用 npm 5.6.0 在 Windows 10 上安装模块。当我输入 npm install 我得到:

gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (C:\Users\xiaooming\Desktop\app\node_modules\node-gyp\lib\configure.js:336:16)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "C:\\Users\\xiaooming\\Desktop\\app\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\Users\xiaooming\Desktop\app\node_modules\node-sass
gyp ERR! node -v v8.10.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
Build failed with error code: 1
npm WARN kingt4.0app@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: 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\xiaooming\AppData\Roaming\npm-cache\_logs\2018-03-18T13_02_03_946Z-debug.log

似乎是 node-sass 安装错误。环境如下:

python版本:2.7.14

npm 版本:5.6.0

节点版本:8.10.0

ruby 版本:2.3.3p222(2016-11-21 修订版 56859)[i386-mingw32]

系统:win10(x64)

节点gyp:3.6.2

我已经安装了 Microsoft Visual Studio express 2015, 下面的命令已经执行:

npm config set msvs_version 2015
node-gyp configure --msvs_version=2015
npm install --global --production windows-build-tools

package.json 是:

{
  "name": "kingt4.0app",
  "version": "1.0.0",
  "description": "an kingt4.0 project.",
  "main": "index.js",
  "scripts": {
    "test": "test.js"
  },
  "keywords": [
    "finance"
  ],
  "author": "kingdom",
  "license": "ISC",
  "devDependencies": {
    "browser-sync": "^2.11.1",
    "gulp": "^3.9.1",
    "gulp-autoprefixer": "^3.1.0",
    "gulp-cache": "^0.4.2",
    "gulp-changed": "^1.3.2",
    "gulp-clean-css": "^2.0.2",
    "gulp-file-include": "^0.13.7",
    "gulp-if": "^2.0.0",
    "gulp-imagemin": "^2.4.0",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^2.2.0",
    "gulp-sourcemaps": "^1.6.0",
    "gulp.spritesmith": "^6.2.1",
    "imagemin-jpegtran": "^4.3.2",
    "imagemin-pngquant": "^4.2.2",
    "merge-stream": "^1.0.0",
    "normalize.css": "^4.0.0",
    "spritesheet-templates": "^10.1.2",
    "vinyl-buffer": "^1.0.0"
  },
  "dependencies": {
    "remodal": "^1.0.7",
    "slick-carousel": "^1.6.0"
  }
}

如何解决这个问题?感谢您的帮助。

【问题讨论】:

标签: node.js windows npm npm-install


【解决方案1】:

删除您的$HOME/.node-gyp 目录并重试:

rm -R ~/.node-gyp

【讨论】:

    【解决方案2】:

    我觉得删除这个目录比较好:

    rm -rf ~/.node-gyp/
    rm -r node_modules/.bin/;
    rm -r build/
    npm install <your module>
    

    【讨论】:

      【解决方案3】:

      如此处所述:https://github.com/nodejs/node-gyp/issues/1634

      You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
      gyp: Call to '/usr/bin/pg_config --libdir' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
      

      在我的情况下,通过在我的 Ubuntu 上安装 libpq-dev 解决了问题

      $ sudo apt install libpq-dev
      

      然后尝试删除node_modules 并再次执行npm install

      注意 请注意,这不是节点模块的问题,问题出在我的机器上,不符合libpq的标准

      【讨论】:

      • npm 错误!代码 E404 npm 错误! 404 未找到 - 获取 registry.npmjs.org/libpq-dev - 未找到
      • 这不是 NPM 模块 @PirAbdul,它在你的机器上。为你的操作系统找到一个匹配模块,在我的例子中是 Ubuntu。根据您使用的内容,您的可能会有所不同。请仔细阅读。
      • 我运行 sudo apt install libpq-dev - 我的问题已解决
      【解决方案4】:

      您可能需要安装 Windows 构建工具。 看看这个ref

      【讨论】:

        【解决方案5】:

        这对我有用。下面的命令一一运行

        rm -rf node_modules
        rm package-lock.json
        npm update
        npm install
        

        【讨论】:

        • 完美 - 这对我有用(虽然不需要 npm update 步骤)
        • 对我没用。
        【解决方案6】:

        我在OSX 10.15 上遇到了同样的问题,brew 作为存储库;对我来说已经足够了:

        brew unlink python@2
        brew link python
        

        【讨论】:

          【解决方案7】:

          如果这是一台 Mac 机器 (OSX),你可以这样做

          使用终端

          xcode-select --print-path
          

          然后删除已安装的版本

          sudo rm -r -f /Library/Developer/CommandLineTools
          

          然后重新安装

          xcode-select --install
          

          应该可以解决问题

          参考:gyp: No Xcode or CLT version detected macOS Catalina

          【讨论】:

          • 就个人而言,我需要每年做几次。 ?‍♂️
          • 这个命令有效。但就像马克吐温一样,我最终会定期重复。
          • 这对我也有用。运行这些命令大约需要一分钟,所以它非常快。谢谢!
          • 谢谢。它就像魅力一样。
          【解决方案8】:

          试试下面的这个命令,看看是否能解决这个问题。我的 Mac 上有 catalina,这个命令解决了这个问题。

          
          npm i -g node-gyp@latest && npm config set node_gyp "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js"
          

          【讨论】:

          • 我运行了 npm i -g node-pre-gyp@latest 并解决了我的问题。这是在运行 Big Sur 的 Mac 上
          【解决方案9】:

          仅适用于 MAC

          步数:1

          sudo rm -r -f /Library/Developer/CommandLineTools
          

          步骤:2

          sudo xcode-select --switch /Library/Developer/CommandLineTools/
          

          【讨论】:

          • 这有什么帮助?你介意解释你的解决方案。您应该在xcode-select --install 上方的 --switch 命令之前执行此命令
          【解决方案10】:

          如果你删除你的 package-lock.json 然后运行

          npm update
          npm install
          

          【讨论】:

            【解决方案11】:

            我在安装使用 webpack 的项目时遇到了同样的问题。 我确实遵循了有关 xcode-select 重新安装的步骤,但它给了我同样的错误。为此我做了一个简单的修复,我单独安装了 node-sass,因为它是错误的。

            npm i node-sass
            

            然后使用,再次运行安装,

            npm i
            

            它对我有用✌️

            有时节点包的版本较旧,项目也需要升级。为此,您在安装时会收到与漏洞相关的警告。为此运行以下命令(在终端输出中也提到),

            npm audit fix
            

            【讨论】:

              【解决方案12】:

              我遇到了类似的问题,我的 MSVS_version 是 2019。我尝试了以下步骤并解决了问题。

              npm install --global --production windows-build-tools
              

              然后

              npm config set msvs_version 2017
              npm i
              

              【讨论】:

              • 我的操作系统:Windows 10..那么,安装windows-build-tools后是否需要重启?
              • 是的尝试这样做
              • Win 7 无需重新启动。衷心感谢您结束 6 小时的冒险来解决此问题。
              【解决方案13】:

              如果你看过一些旧教程并想从 NPM 安装 webworker-threads,你应该知道它是 Node JS 的一部分。

              const { Worker } = require('worker_threads');
              

              您可以在此处查看有关差异的更多信息 https://nodejs.org/api/worker_threads.html

              【讨论】:

                【解决方案14】:

                这个错误是由于包过时造成的,也可能是由于nodejs,npm或其他包以及包管理器的版本变化,要解决这个问题,你必须删除节点模块并执行命令:

                npm i --ignore-script
                

                可能 node-sass 给你一个错误,因为它已经过时了,所以安装 npm sass 或者如果它是任何其他包,只需检查当前版本并更新它

                【讨论】:

                  【解决方案15】:

                  我必须更新到 dart-sass,仍在使用已弃用的 node-sass。 https://github.com/sass/dart-sass#from-npm

                  【讨论】:

                    【解决方案16】:
                    $ npm i --ignore-script 
                    

                    我尝试了不同的方法来解决这个问题,最后,这条评论只是帮助安装节点包没有任何错误。

                    【讨论】:

                      猜你喜欢
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      • 2014-10-20
                      • 1970-01-01
                      • 1970-01-01
                      • 2020-04-26
                      • 1970-01-01
                      • 2018-04-27
                      相关资源
                      最近更新 更多