npm安装失败,因为node-gyp失败。怎么修?

时间:2017-08-23 01:43:06

标签: node.js npm node-gyp

我最近尝试为我们的项目进行全新安装。但是现在npm install在Ubuntu 17.04上失败了。我已经改变了我正在使用的节点,npm,node-gyp和python的版本,但没有成功。

这是由于node-gyp还是其他原因的变化? 跑步:

 node-gyp rebuild

给我:

    gyp info it worked if it ends with ok
    gyp info using node-gyp@3.6.2
    gyp info using node@7.10.1 | linux | x64
    gyp info spawn /usr/bin/python2
    gyp info spawn args [ '/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py',
    gyp info spawn args   'binding.gyp',
    gyp info spawn args   '-f',
    gyp info spawn args   'make',
    gyp info spawn args   '-I',
    gyp info spawn args   '/home/joel/workspace/Tracker3/build/config.gypi',
    gyp info spawn args   '-I',
    gyp info spawn args   '/usr/local/lib/node_modules/node-gyp/addon.gypi',
    gyp info spawn args   '-I',
    gyp info spawn args   '/home/joel/.node-gyp/7.10.1/include/node/common.gypi',
    gyp info spawn args   '-Dlibrary=shared_library',
    gyp info spawn args   '-Dvisibility=default',
    gyp info spawn args   '-Dnode_root_dir=/home/joel/.node-gyp/7.10.1',
    gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/node-gyp',
    gyp info spawn args   '-Dnode_lib_file=/home/joel/.node-gyp/7.10.1/<(target_arch)/node.lib',
    gyp info spawn args   '-Dmodule_root_dir=/home/joel/workspace/Tracker3',
    gyp info spawn args   '-Dnode_engine=v8',
    gyp info spawn args   '--depth=.',
    gyp info spawn args   '--no-parallel',
    gyp info spawn args   '--generator-output',
    gyp info spawn args   'build',
    gyp info spawn args   '-Goutput_dir=.' ]
    gyp info spawn make
    gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
    make: Entering directory '/home/joel/workspace/Tracker3/build'
    make: *** No rule to make target 'Release/obj.target/binding/src/binding.o', needed by 'Release/obj.target/binding.node'.  Stop.
    make: Leaving directory '/home/joel/workspace/Tracker3/build'
    gyp ERR! build error 
    gyp ERR! stack Error: `make` failed with exit code: 2
    gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:258:23)
    gyp ERR! stack     at emitTwo (events.js:106:13)
    gyp ERR! stack     at ChildProcess.emit (events.js:194:7)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
    gyp ERR! System Linux 4.11.3-041103-generic
    gyp ERR! command "/home/joel/.nvm/versions/node/v7.10.1/bin/node" "/usr/local/bin/node-gyp" "rebuild"
    gyp ERR! cwd /home/joel/workspace/Tracker3
    gyp ERR! node -v v7.10.1
    gyp ERR! node-gyp -v v3.6.2
    gyp ERR! not ok

有没有人有什么想法导致这个?以及如何调试和修复?

4 个答案:

答案 0 :(得分:0)

在ubuntu上运行此命令sudo apt-get install build-essential并再次尝试。

另请参阅此处推荐的here

有关如何重新启动的详细信息,您可以看到here

答案 1 :(得分:0)

现在这是一个答案!事实证明,有一个遗留下来的“绑定”。在导致所有问题的项目的根目录,因为它无法构建任何东西!当然,我首先假设这是因为包装完全错误....

简化并删除所有内容:

{
  "name": "Tracker3",
  "version": "3.1.0",
  "description": "A todo list and shared tracker",
  "keywords": [
    "angular",
    "angular4",
    "webpack",
    "typescript"
  ],
  "author": "Joel Parke <joel@Dynazu.com>",
  "homepage": "https://github.com/AngularClass/angular-starter",
  "license": "UNLICENSED",
  "scripts": {
  },
  "dependencies": {
  },
  "devDependencies": {
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/AngularClass/angular-starter.git"
  },
  "bugs": {
    "url": "https://github.com/AngularClass/angular-starter/issues"
  },
  "engines": {
    "node": ">= 4.2.1",
    "npm": ">= 3"
  }
}

包里根本没有任何内容现在给出:

yarn
yarn install v0.27.5
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
$ node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@3.5.0
gyp info using node@7.10.1 | linux | x64
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/home/joel/.nvm/versions/node/v7.10.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/home/joel/workspace/Tracker3/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/joel/.nvm/versions/node/v7.10.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/joel/.node-gyp/7.10.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/home/joel/.node-gyp/7.10.1',
gyp info spawn args   '-Dnode_gyp_dir=/home/joel/.nvm/versions/node/v7.10.1/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=node.lib',
gyp info spawn args   '-Dmodule_root_dir=/home/joel/workspace/Tracker3',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/joel/workspace/Tracker3/build'
make: *** No rule to make target 'Release/obj.target/binding/src/binding.o', needed by 'Release/obj.target/binding.node'.  Stop.
make: Leaving directory '/home/joel/workspace/Tracker3/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/joel/.nvm/versions/node/v7.10.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:194:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Linux 4.12.0-041200-generic
gyp ERR! command "/home/joel/.nvm/versions/node/v7.10.1/bin/node" "/home/joel/.nvm/versions/node/v7.10.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/joel/workspace/Tracker3
gyp ERR! node -v v7.10.1
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok 
error Command failed with exit code 1.

所以事实证明这个&#39; binding.gyp&#39;在某些时候遗留下来的文件导致了所有问题。   删除此文件并恢复所有内容会产生:

yarn:

yarn install v0.27.5
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.12s.
joel@parke:~/workspace/Tracker3$ yarn
yarn install v0.27.5
[1/4] Resolving packages...
[2/4] Fetching packages...
warning fsevents@1.1.2: The platform "linux" is incompatible with this module.
info "fsevents@1.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "ngrx-store-freeze@0.1.9" has incorrect peer dependency "@ngrx/store@^2.2.1".
[4/4] Building fresh packages...
success Saved lockfile.
$ npm run webdriver:update

> Tracker3@3.1.0 webdriver:update /home/joel/workspace/Tracker3
> webdriver-manager update

webdriver-manager: using local installed version 12.0.6
[12:02:08] I/file_manager - creating folder /home/joel/workspace/Tracker3/node_modules/webdriver-manager/selenium
[12:02:09] I/update - chromedriver: unzipping chromedriver_2.31.zip
[12:02:09] I/update - chromedriver: setting permissions to 0755 for /home/joel/workspace/Tracker3/node_modules/webdriver-manager/selenium/chromedriver_2.31
[12:02:11] I/update - geckodriver: unzipping geckodriver-v0.18.0.tar.gz
[12:02:11] I/update - geckodriver: setting permissions to 0755 for /home/joel/workspace/Tracker3/node_modules/webdriver-manager/selenium/geckodriver-v0.18.0
Done in 36.46s.

这是正确的预期。希望这会在某些时候帮助别人!感谢所有看过这个的人!特别是,https://stackoverflow.com/users/8377060/jack-delson

答案 2 :(得分:0)

获取“无规则可致目标...”错误的最简单方法是使binding.gyp中指定的文件错误。如果找不到sources键中的文件名,则会出现此错误。

答案 3 :(得分:0)

我遇到了同样的问题,可以通过以下操作解决:

  1. 已删除旧的命令行工具

    sudo rm -rf $(xcode-select -print-path)

    并重新安装:

    xcode-select --install

  2. 将节点版本从11降级到8.16.1

    sudo npm install -g n

    稳定稳定

    sudo n 8.16.1

    最后,检查您的节点版本:

    节点-v