运行npm start时出现错误:nvm与"npm_config_prefix"环境变量不兼容。

6
我正在处理一个使用nvm的项目。
不知何故,当我运行“npm start”时,开始出现以下错误:
npm start

> sh ./bin/start.sh

nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/Users/user/.nvm/versions/node/v8.9.4"
Run `unset npm_config_prefix` to unset it.
Found '/Users/user/project/project/.nvmrc' with version <8.9.0>
nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/Users/user/.nvm/versions/node/v8.9.4"
Run `unset npm_config_prefix` to unset it.
/Users/user/project/project/node_modules/node-sass/lib/binding.js:15
      throw new Error(errors.missingBinary());
      ^

Error: Missing binding /Users/user/project/project/node_modules/node-sass/vendor/darwin-x64-59/binding.node
Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 9.x

Found bindings for the following environments:
  - OS X 64-bit with Node.js 8.x

This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass --force` to build the binding for your current environment.
    at module.exports (/Users/user/project/project/node_modules/node-sass/lib/binding.js:15:13)
    at Object.<anonymous> (/Users/user/project/project/node_modules/node-sass/lib/index.js:14:35)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/user/project/project/node_modules/node-sass/bin/node-sass:10:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @namespace/project@5.14.1 start: `sh ./bin/start.sh`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @namespace/project@5.14.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/user/.npm/_logs/2018-06-19T19_30_15_079Z-debug.log

我已经尝试了以下操作,但都没有成功:

1)删除仓库,重新克隆并运行npm install

2)更新npm

3)删除nvm文件夹并重新下载

4)运行unset npm_config_prefix

5)运行npm rebuild node-sass --force

注:我在Mac OS 10.13.4上使用zsh终端。


你尝试过运行:unset npm_config_prefix 吗? - Miguel Ortiz
@MiguelOrtiz 是的,我做了。 - Leandro
尝试完全卸载node,不要忘记检查每个文件,这是一个不错的清单:https://gist.github.com/TonyMtz/d75101d9bdf764c890ef - Miguel Ortiz
嗨,我遇到了和你一样的问题,你解决了吗? - sammiepls
2个回答

0
如果使用nvm而不是系统节点,显然可以将以下行添加到批处理文件中: unset NPM_CONFIG_PREFIX 或在终端中运行。

但是如何确保它仅适用于npm脚本调用的持续时间? - Mike 'Pomax' Kamermans
不应该这样。如果您使用由nvm管理的node或npm(而不是系统的node/npm),那么所有全局包都必须在~/.nvm/versions/node/下的特定版本中。 - Paul Verest

0

我像这里建议的那样运行了nvm deactivate,然后错误消息消失了。 我只运行了这一个命令,没有运行其他命令。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接