Search code examples
eslintvisual-studio-codenvm

How to set nvm and ESLint with VSCode globally?


I want vscode eslint extensions works with nvm.

I got "Install ESLint global with npm install -g eslint" in vscode eslint estension console.

So, I've installed the eslint with nvm in terminal with npm install -g eslint, and set it, which in the path:

/Users/myname/.nvm/versions/node/v10.16.0/lib/node_modules

Try to review the official docs, and find one solution to set eslint.nodePath in settings.json.

settings.json of vscode:

  "eslint.nodePath": "/Users/myname/.nvm/versions/node/v10.16.0/lib/node_modules",

After set this property, the extension works well.

But, it would broke when I change node versions use nvm. I need to re-set settings.json.

Is there any solutions to set eslint in vscode with nvm?

I don't want to set settings.json when I change node versions with nvm each time.

I want to do it simple.

Thx.


Solution

  • I figure it out after few hours hard work.

    1. do NOT use fish as mac's default shell

    2. set vscode user settings to:

      "terminal.integrated.shell.osx": "/usr/local/bin/fish",
    

    that you can use fish in vscode terminal

    install fisher, use

    fisher add FabioAntunes/fish-nvm
    fisher add edc/bass
    

    that you can use nvm with fish

    1. set your .bash_profile of nvm and nvm variables:
    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
    

    add

    fish
    

    at the bottom

    1. If you want to switch bash and fisher use:
    # fish -> bash
    bash --login 
    
    # bash -> fish
    fish
    
    1. Enjoy fish and nvm and eslint vscode plugin

    This will output of vscode console.

    [Info  - 12:04:44 PM] ESLint server stopped.
    [Info  - 12:04:45 PM] ESLint server running in node v10.11.0
    [Info  - 12:04:45 PM] ESLint server is running.