【问题标题】:Installing NodeJS contextify package yields an error安装 NodeJS contextify 包会产生错误
【发布时间】:2023-04-01 13:56:01
【问题描述】:

我已经学习了 1 小时 NodeJS,所以请耐心等待。我的项目需要的包之一是 JSDom。在浏览了大部分 Internet 之后,我发现 JSDOm 有一个称为 contextify 的依赖项,它在 JSDom 安装本身中以某种方式进行了处理。所以这就是我的工作:

sudo npm install jsdom 

一切顺利,直到我得到以下信息:

gyp WARN install got an error, rolling back install
gyp ERR! rebuild error Error: EACCES, stat '/root/.node-gyp/0.8.2'
gyp ERR! not ok
npm ERR! contextify@0.1.7 install: `node-gyp rebuild`
npm ERR! `sh "-c" "node-gyp rebuild"` failed with 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.2.0-60-generic
npm ERR! command "/opt/node/bin/node" "/opt/node/bin/npm" "install" "contextify"
npm ERR! cwd /opt/node
npm ERR! node -v v0.8.2
npm ERR! npm -v 1.1.36
npm ERR! code ELIFECYCLE
npm ERR! message contextify@0.1.7 install: `node-gyp rebuild`
npm ERR! message `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /opt/node/npm-debug.log
npm ERR! not ok code 0

难倒!!!

我发现要在 Ubuntu 上运行 contextify,我必须有 make、python 和 G++。我都有。那么我到底错过了什么?

仅供参考,JSDOM 安装尝试之前的命令是:

mkdir ~/.node-gyp
chmod -R 777 ~/.node-gyp

我也尝试了以下方法:

npm install -g node-gyp
npm install contextify

在第二个命令中,我遇到了同样的问题。

【问题讨论】:

  • 您可能需要执行 sudo npm install -g npm 并重试(它在我的 Mac 上有效)或查看此 stackoverflow.com/questions/21148917/…。如果你在节点上做了一个标准的 apt-get,它很可能已经落后了,采用最新的捆绑包版本可能会解决它
  • 我会先升级到更新版本的 Node.js。您正在运行 0.8.2(甚至不是 0.8.x 系列中的最新版本),但 0.10.26 是最新的稳定版本。
  • @KeepCalmAndCarryOn 就是这样,我做到了,一切正常!
  • 你应该发布这个作为答案,我会接受
  • 我把它作为答案发布了,谢谢

标签: node.js npm jsdom node-gyp contextify


【解决方案1】:

你可能需要这样做

sudo npm install -g npm

然后再试一次(它在我的 mac 上工作)

或查看Error installing contextify- node-gyp rebuild failed

如果你在节点上做了一个标准的 apt-get,它很可能会落后于时代,而采用最新的捆绑包版本可能会解决它

【讨论】:

    【解决方案2】:

    情况变了:jsdom >= 4.0.0 no longer uses contextify:

    4.0.0

    此版本依赖于 io.js 新大修的 vm 模块,以消除 Contextify 原生模块依赖。 jsdom 现在应该更易于使用和安装,无需 C++ 编译器工具链!

    如果您需要没有上下文的旧版本,请尝试jsdom-no-contextify

    【讨论】:

      【解决方案3】:

      node-gyp EACCES 可以通过更改访问权限和有时为 npm 设置 node-gyp python 版本来解决,如下所示:

      sudo chown -R $USER /usr/local
      

      npm config set python /usr/bin/python2.7
      

      (将 python2.7 更改为 python2.6,具体取决于相关版本)

      【讨论】:

        猜你喜欢
        • 2014-10-05
        • 1970-01-01
        • 2013-05-11
        • 1970-01-01
        • 2014-11-29
        • 2018-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多