gpt4 book ai didi

node.js - 设置NODE_PATH

转载 作者:太空宇宙 更新时间:2023-11-03 22:14:30 24 4
gpt4 key购买 nike

我安装了nvm,并用它来升级node:nvm install 4.2.1。我更新了 .bashrc 以导出 NODE_PATH=$HOME/.nvm/versions/node/v4.2.1/lib/node_modules

我的近期目标是安装 hubot,遵循 these instructions 。安装命令成功:npm install -g hubot Coffee-script yo Generator-hubot

但是安装的命令找不到它们的库:

$ yo hubot
module.js:339
throw err;
^

Error: Cannot find module 'os-tmpdir'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/home/john/.nvm/versions/node/v4.2.1/lib/node_modules/yo/node_modules/configstore/node_modules/osenv/osenv.js:4:16)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)

当我安装每个丢失的库时,它被发现了。所以我最终遇到了这种情况:

# We already have two copies of os-tmpdir, why isn't it found??
$ find /home/john/.nvm/ -name "*tmpdir*"
/home/john/.nvm/versions/node/v4.2.1/lib/node_modules/generator-hubot/node_modules/os-tmpdir
/home/john/.nvm/versions/node/v4.2.1/lib/node_modules/npm/node_modules/osenv/node_modules/os-tmpdir

# Just install it again:
$ npm install -g os-tmpdir

# Now we have three copies! But it's being found.
$ find /home/john/.nvm/ -name "*os-tmpdir*"
/home/john/.nvm/versions/node/v4.2.1/lib/node_modules/generator-hubot/node_modules/os-tmpdir
/home/john/.nvm/versions/node/v4.2.1/lib/node_modules/npm/node_modules/osenv/node_modules/os-tmpdir
/home/john/.nvm/versions/node/v4.2.1/lib/node_modules/os-tmpdir

为什么 Node 模块没有一个node_modules?是否应该有 node_modules 嵌套在 node_modules 下嵌套在 node_modules ... 下?

最佳答案

来自 npm 3.0.0 release notes :

Your dependencies will now be installed maximally flat. Insofar as is possible, all of your dependencies, and their dependencies, and THEIR dependencies will be installed in your project's node_modules folder with no nesting. You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies.

至于 nvm...我偶尔会遇到路径问题。它做得很好,但我不得不像你一样进行一些调整。对我来说,过去的根本原因是 npm 的重大升级(就像这里,如果你已经这样做了)或坏的 .npmrc 文件(哎呀......)。典型的缓存清理、卸载重新安装通常可以为我修复它。

在这种情况下,初始安装是在安装 nvm 和升级 Node 之前完成的。这解决了问题:

$ npm uninstall -g hubot coffee-script yo generator-hubot
$ npm install -g hubot coffee-script yo generator-hubot

关于node.js - 设置NODE_PATH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33499725/

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