簡體   English   中英

npm安裝 <module> 持久性錯誤? (node-gyp build?)

[英]npm install <module> persistent error ? (node-gyp build ?)

我嘗試安裝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.

在此輸入圖像描述

如何解決?


編輯:我嘗試了sudo apt-get remove --purge nodejs npm topojson然后通過各種方式重新安裝。 即使nodejs重新安裝成功,錯誤仍然存​​在 ,所以我猜它更像是上下文( node.gypcwd ?...)。 刪除/重新安裝嘗試的方法:

正如您從評論中發現的那樣,這是一個非常常見的問題。 事實上,jsdom的作者已經在項目的git存儲庫的README文件中記錄了它。


TL; DR

你需要在你的機器上安裝一個C ++編譯器和Python2.7來安裝contextify ,這是jsdom的依賴。 否則,jsdom安裝將失敗。


來自jsdomGithub頁面上的README:

Contextify

Contextify是jsdom的依賴項,用於在頁面中運行<script>標記。 換句話說,它允許在Node.js中運行的jsdom在假裝成瀏覽器環境而不是服務器的隔離環境中運行JavaScript字符串。 您可以看到這是一個重要的功能。

不幸的是,做這種魔術需要C ++。 在Node.js中,使用JavaScript中的C ++意味着使用“本機模塊”。 本機模塊在安裝時編譯,以便它們可以精確地為您的機器工作; 也就是說,你不從npm下載一個contextify二進制文件,而是在從npm下載源代碼后在本地構建一個。

不幸的是,在npm的安裝系統中編譯C ++可能會很棘手,特別是對於Windows用戶。 因此,jsdom最常見的問題之一是在沒有安裝適當的編譯工具的情況下嘗試使用它。 以下是編譯Contextify所需的內容,從而安裝jsdom:

視窗

  • 用於Windows的x86版本的Node.js的最新副本,而不是x64版本。
  • Visual C ++ 2010 Express的副本。
  • Python 2.7的副本,安裝在C:\\ Python27的默認位置。

對此有一些細微的修改可以起作用; 例如,Visual Studio的完整版本通常可以工作,有時你甚至可以獲得一個x64版本的Node.js。 但它很棘手,所以從基礎開始吧!

蘋果電腦

  • 需要安裝XCode
  • 需要安裝“XCode的命令行工具”
  • 啟動XCode一次以接受許可證等,並確保正確安裝

Linux的

您需要安裝各種構建工具,如make,Python 2.7和編譯器工具鏈。 如果您還沒有這些,那么如何安裝這些將特定於您的發行版。

在滿足上面提到的操作系統要求后再嘗試安裝jsdom ,看看是否能解決問題。

順便說一句,你在topojson中遇到了同樣的問題,因為它依賴於d3 ,而d3又依賴於jsdom ,所以安裝jsdom也是同樣的問題。 希望這可以幫助!

- 編輯 -

既然聽起來你正在使用Ubuntu,我建議從以下命令開始:

sudo apt-get install build-essential

這將安裝makeg ++以及其他一些工具。 這個包和Python2.7可能是您成功安裝contextify所需的全部內容。

似乎我通過仔細刪除計算機上所有與節點相關的文件和文件夾找到了一種方法。

背景:我之前做過幾次不成功的控制台清理工作

sudo apt-get remove --purge nodejs npm topojson

接下來是~3種不同的方法來重新安裝nodejs 我嘗試了每種方式,從清理到重新安裝,在2到4次之間。

1.終端清除:讓我們以最深的方式清理我的爛攤子:

npm cache clean; bower cache clean; grunt clean;
sudo apt-get remove --purge nodejs npm topojson

然而,我只是注意到這個深度清除不會清除/刪除已安裝的節點模塊 ,這些模塊保持持久性。

2.手動清洗:另外,我用手清洗進一步推動清洗,用於nodejsnode_modules 我在我的計算機上尋找所有相關文件夾,更接近根(ubuntu: /home/<user>/ )。 我小心刪除所有以前安裝的全局.../node-modules/文件夾,而不刪除本地模塊(特定的本地安裝,仍在工作)。

3.重新安裝:然后以下控制台允許干凈的重新安裝:

sudo apt-get update
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

sudo npm install -g topojson jsdom

之后,通過npm模塊topojson (取決於jsdom )的文件轉換工作正常:

cd /myfolder/
topojson -o output.topo.json input.geo.json   

4.結論:我無法確定為什么,哪個文件/文件夾刪除允許成功的sudo apt-get install nodejs + sudo npm install -g topojson重新安裝。 但是通過鼠標進行深度清理並遞歸刪除sudo rm -r [node related folder/file]最終解鎖了我的情況。

/!\\ 小心 rm -r遞歸刪除 /!\\

解決方案1b:我[懷疑] [1] rm -r /home/<user>/local/lib/node_modules/是解鎖情況的關鍵元素。 您可以列出全局( -g )node_modules,然后專門刪除相關的一個( topojson和/或jsdom和/或node-gyp jsdom ),然后重新安裝它們(它們)。

命令:在ubuntu上,試試......

 cd /home/<user>/local/lib/node_modules/  #replace <user> by relevant user name to set your cwd
 ls -1      # give the list of global modules names
 rm -r /<module_name>    #replace <module_name> by relevant name to remove it
 sudo npm install -g <module_name>  #replace <module_name> by relevant name for global install

注意: topojson依賴於jsdomnpm-gyp jsdom

[1]:沒試過,但根據我的診斷有意義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM