'Error when running npm start: nvm is not compatible with the "npm_config_prefix" environment variable

I am working on a project which I use nvm.

Out of nowhere, I started to get this error when running "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/[email protected] start: `sh ./bin/start.sh`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @namespace/[email protected] 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

I have already tried the following actions with no success:

1) Delete the repo, clone it again and run npm install

2) Update npm

3) Delete nvm folder and download it again

4) Run unset npm_config_prefix

5) Run npm rebuild node-sass --force

Obs.: I use zsh terminal on a Mac OS 10.13.4



Solution 1:[1]

I ran nvm deactivate as suggested here and the error went away. I only ran that command and none of the other ones.

Solution 2:[2]

If using nvm and not system node Obviously one can add line

unset NPM_CONFIG_PREFIX

into a batch file. Or run it in terminal

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jonathan Morales VĂ©lez
Solution 2