gpt4 book ai didi

node.js - npm install 持续错误? ( Node gyp 构建?)

转载 作者:搜寻专家 更新时间:2023-10-31 22:18:35 24 4
gpt4 key购买 nike

我尝试这样安装 jsdom:

$ sudo npm install -g jsdom
# OR
$ sudo npm install jsdom

在一些成功的命令之后,安装很快失败,第一条错误消息出现在 [....] 之后:

$ sudo npm install jsdom 
npm http GET https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/jsdom
[....]

> contextify@0.1.7 install /home/yug/Desktop/QGis/WikiAtlas/1_shaded_relief/test/node_modules/jsdom/node_modules/contextify
> node-gyp rebuild

gyp: /home/yug/.node-gyp/0.10.25/common.gypi not found (cwd: /home/yug/Desktop/QGis/WikiAtlas/1_shaded_relief/test/node_modules/jsdom/node_modules/contextify) while reading includes of binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:337:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.8.0-35-generic
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/yug/Desktop/QGis/WikiAtlas/1_shaded_relief/test/node_modules/jsdom/node_modules/contextify
gyp ERR! node -v v0.10.25
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm http 304 https://registry.npmjs.org/domhandler
npm http 304 https://registry.npmjs.org/domelementtype
npm ERR! contextify@0.1.7 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the contextify@0.1.7 install script.
npm ERR! This is most likely a problem with the contextify package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls contextify
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.8.0-35-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "jsdom"
npm ERR! cwd /home/yug/Desktop/QGis/WikiAtlas/1_shaded_relief/test
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! code ELIFECYCLE

npm http 304 https://registry.npmjs.org/qs
npm http 304 https://registry.npmjs.org/entities
....

提示?此错误也出现在其他模块中:

 $sudo npm install -g topojson 
#bug with `contextify@0.1.7 install` error as well.

enter image description here

如何解决?


编辑:我尝试了 sudo apt-get remove --purge nodejs npm topojson 然后通过各种方式重新安装。 即使 nodejs 重新安装成功,错误仍然存​​在,所以我猜这是相当上下文相关的(node.gyp ? cwd ? ...)。删除/重新安装尝试的方法:

最佳答案

正如您从评论中发现的那样,这是一个非常普遍的问题。如此普遍,事实上,jsdom 的作者已经在项目的 git 存储库的 README 文件中记录了它。


长话短说

您需要在计算机上安装 C++ 编译器和 Python2.7 才能安装 contextify,它是 jsdom 的依赖项。否则,jsdom 安装将失败。


来自 Github page for jsdom 上的自述文件:

Contextify

Contextify is a dependency of jsdom, used for running <script> tags within the page. In other words, it allows jsdom, which is run in Node.js, to run strings of JavaScript in an isolated environment that pretends to be a browser environment instead of a server. You can see how this is an important feature.

Unfortunately, doing this kind of magic requires C++. And in Node.js, using C++ from JavaScript means using "native modules." Native modules are compiled at installation time so that they work precisely for your machine; that is, you don't download a contextify binary from npm, but instead build one locally after downloading the source from npm.

Unfortunately, getting C++ compiled within npm's installation system can be tricky, especially for Windows users. Thus, one of the most common problems with jsdom is trying to use it without the proper compilation tools installed. Here's what you need to compile Contextify, and thus to install jsdom:

Windows

  • A recent copy of the x86 version of Node.js for Windows, not the x64 version.
  • A copy of Visual C++ 2010 Express.
  • A copy of Python 2.7, installed in the default location of C:\Python27.

There are some slight modifications to this that can work; for example full versions of Visual Studio usually work, and sometimes you can even get an x64 version of Node.js working too. But it's tricky, so start with the basics!

Mac

  • XCode needs to be installed
  • "Command line tools for XCode" need to be installed
  • Launch XCode once to accept the license, etc. and ensure it's properly installed

Linux

You'll need various build tools installed, like make, Python 2.7, and a compiler toolchain. How to install these will be specific to your distro, if you don't already have them.

在满足上述操作系统要求后,再次尝试安装 jsdom,看看是否能解决问题。

顺便说一句,你在 topojson 上遇到了同样的问题,因为它依赖于 d3,而 d3 又依赖于 jsdom,所以安装jsdom也是同样的问题。希望这对您有所帮助!

--编辑--

由于听起来您使用的是 Ubuntu,因此我建议您从以下命令开始:

sudo apt-get install build-essential

这将安装ma​​keg++ 以及一些其他工具。这个包和 Python2.7 可能是您成功安装 contextify 所需的全部。

关于node.js - npm install <module> 持续错误? ( Node gyp 构建?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23053425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com