Search code examples
npmvisual-studio-codevi

How to edit npm config file with visual-studio-code?


The default editor of npm config is vi. After read this docs: https://docs.npmjs.com/misc/config#editor

☁  nodejs-project  npm get editor
vi

Now, I want to edit npm config using visual-studio-code

So, I set npm editor to visual-studio-code like this:

☁  nodejs-project  npm set editor visual-studio-code
☁  nodejs-project  npm get editor
visual-studio-code

And, try this command, got an error:

☁  nodejs-project  npm config edit
npm ERR! path visual-studio-code
npm ERR! code ENOENT
npm ERR! errno ENOENT
npm ERR! syscall spawn visual-studio-code
npm ERR! enoent spawn visual-studio-code ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/ldu020/.npm/_logs/2019-01-18T03_00_59_872Z-debug.log

Solution

  • Check vscode binary:

    ☁  nodejs-project  brew cask info visual-studio-code
    visual-studio-code: 1.30.2,61122f88f0bf01e2ac16bdb9e1bc4571755f5bd8 (auto_updates)
    https://code.visualstudio.com/
    /usr/local/Caskroom/visual-studio-code/1.22.2,3aeede733d9a3098f7b4bdc1f66b63b0f48c1ef9 (64B)
    From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/visual-studio-code.rb
    ==> Names
    Microsoft Visual Studio Code
    VS Code
    ==> Artifacts
    Visual Studio Code.app (App)
    /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code (Binary)
    

    It should set npm editor to code, not visual-studio-code

    ☁  nodejs-project  npm set editor code
    ☁  nodejs-project  npm get editor
    code
    

    Now, npm config edit will use vscode open .npmrc file.