Node.js - Configuring $NODE_PATH with NVM

后端 未结 3 1453
醉话见心
醉话见心 2020-12-30 21:14

On my way setting up Node.js with NVM, I stumbled upon an error when using Yeoman. I got the error

Cannot find module         


        
相关标签:
3条回答
  • 2020-12-30 21:47

    NVM will set the path for node and npm once you run

    nvm use <node_version>
    

    However, that is just for the current shell and any new shells will not have a version of node an npm selected until your run the previous command unless you set a default version

    nvm alias default <node_version>
    

    voila! You have a working version of npm and node in any new shell you open.

    To change the default simply run it again with the new version of node you want to use. e.g.

    nvm alias default v5.4.0
    
    0 讨论(0)
  • 2020-12-30 21:57

    Adding following to .bashrc or .zshrc helps

    export NODE_PATH=$NODE_PATH:`npm root -g`
    

    I am not expert whether that is good.

    source as pointed out by Pensierinmusica

    0 讨论(0)
  • 2020-12-30 22:01

    I figured a way to make this work.

    In your ~/.bash_rc file or ~/.zsh_rc add this line:

    export NODE_PATH=`which node`
    

    Open new shell or run this source ~/.bash_rc to pick up the changes

    0 讨论(0)
提交回复
热议问题