启动 tmux 时出现 NPM/NVM 错误 : nvm is not compatible with the npm config "prefix" option: currently set to ""

标签 npm tmux nvm

当我使用 tmux 启动新的 tmux session 时, tmux newtmux new-session ,我收到以下错误:

module.js:549
    throw err;
    ^

Error: Cannot find module '../lib/utils/unsupported.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:21
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:153:3)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `npm config delete prefix` or `nvm use --delete-prefix v10.8.0 --silent` to unset it.

我已经尝试过 this question 的解决方案即npm delete prefix但无济于事:在 tmux session 之外运行并不能解决问题,并且在 tmux session 内运行会再次抛出上一个错误的顶部部分(没有 npm 警告):

module.js:549
    throw err;
    ^

Error: Cannot find module '../lib/utils/unsupported.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:21
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:153:3)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)

这似乎是 npm 的一个问题,因为当我运行 npm --help 时也会出现 .js 错误。 。但是,这只发生在 tmux 内。

有什么解决办法吗?

最佳答案

在互联网上挖掘后,我发现了一些可接受的答案:

再次尝试配置 $NVM_DIR 引用。

例如 nvm 使用 v7.10.0,并出现错误:运行 npm config delete prefixnvm use --delete-prefix v7.10.0 --silent 来取消设置。

您需要覆盖 nvm 前缀,

npm 配置集前缀 $NVM_DIR/versions/node/v7.10.0

https://github.com/nvm-sh/nvm/issues/855#issuecomment-314309706

如果您使用 bash 以外的任何其他 shell,请确保以这种方式配置您的 tmux:

# set default shell to zsh
set -g default-command /bin/zsh
set -g default-shell /bin/zsh

这为我解决了这个问题。

https://github.com/nvm-sh/nvm/issues/1245#issuecomment-370396741

在 shell 文件(例如 ~/.zshrc)中注释掉以下代码:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

注销您的帐户并登录

取消上面这些代码和源 shell 文件

nvm unalias default

https://stackoverflow.com/a/47861348/6700273 https://blog.natetodd.com/nvm/

关于启动 tmux 时出现 NPM/NVM 错误 : nvm is not compatible with the npm config "prefix" option: currently set to "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54505117/

相关文章:

javascript - 如何将查询 graphql 转换为 json 对象?

tmux - 多个 tmux 前缀键组合?

node.js - 如何使用 nvm 正确升级 Node

node.js - 使用 nvm-windows 时更新 npm

node.js - MongoDB - 如何使用 Node.js 获取集合的大小?

node.js - Docker - 构建失败,操作系统不受支持,命令 '/bin/sh -c npm install' 返回非零代码

npm - Cypress-webpack-preprocessor 的 Webpack 编译错误

linux - tmux 可以将命令保存到文件中,例如 .bash_history 吗?

linux - 如何通过 tmux 中的任何快捷方式切换到上一个 Pane ?

node.js - 如何使用 nvm 在 Node 安装之间复制全局模块?