volta
volta copied to clipboard
volta + neovim compatibility issues
problem
neovim cannot discover node modules installed globally by volta
investigation
nvim +checkhealth
yields:
## Node.js provider (optional)
- INFO: Node.js: v14.15.0
- WARNING: Missing "neovim" npm (or yarn) package.
- ADVICE:
- Run in shell: npm install -g neovim
- Run in shell (if you use yarn): yarn global add neovim
Given that when using volta, npm i -g and volta global add are discouraged, i run:
volta install neovim
Which still has nvim +checkhealth yielding:
## Node.js provider (optional)
- INFO: Node.js: v14.15.0
- WARNING: Missing "neovim" npm (or yarn) package.
- ADVICE:
- Run in shell: npm install -g neovim
- Run in shell (if you use yarn): yarn global add neovim
Investigating further, neovim's algorithm essentially looks each of the following locations:
npm --loglevel silent root -gyarn global dir(for non unix)'$HOME/.config/yarn/global/'(for unix)
Likely ideal solution
Add volta support to neovim? corresponding neovim issue
Workaround:
The following has volta behave as if it were yarn, which appears to address the issue in question.
volta install yarn
rm -rf $HOME/.config/yarn/global/
mkdir -p $HOME/.config/yarn/global/
ln -s $HOME/.volta/tools/shared/ $HOME/.config/yarn/global/node_modules
yields a functional node.js provider for neovim.
## Node.js provider (optional)
- INFO: Node.js: v14.15.0
- INFO: Neovim node.js host: /Users/spenner/.config/yarn/global//node_modules/neovim/bin/cli.js
- OK: Latest "neovim" npm/yarn package is installed: 4.9.0
@stefanpenner which version of Volta are you using? Our recent 0.9.x releases should have (a) stopped discouraging use of npm i -g or yarn global add and (b) made this work!
@chriskrycho The changes in 0.9.x still didn't quite get this working. neovim itself isn't launched by Volta, so it doesn't pick up the NODE_PATH that makes the neovim package available with require. It looks (given the above-linked issue) like neovim looks in a couple of specific locations for the Node package, and Volta's custom package handling breaks those assumptions.
Ahhhh, that would do it; I misunderstood the dynamics with neovim specifically. Thanks for clarifying, @charlespierce!
@stefanpenner - You have to specify node path in neovim config (init.vim). Please add let g:node_host_prog = system('volta which neovim-node-host | tr -d "\n"') to your neovim config and try again.
@mainendra that is a better workaround than the one I have listed, thank you.
That being said it would be great to make this more seamless.
In the meantime, I've changed my work-around to add the following to my init.vim based on @mainendra's suggestion:
if executable('volta')
let g:node_host_prog = trim(system("volta which neovim-node-host"))
endif
I think we can convert this to enhancement story.
Thanks for your solutions. For me they were not 100% clear, so if anyone had the same problem. It worked with me via this:
local g = vim.g
g["node_host_prog"] = vim.call("system", 'volta which neovim-node-host | tr -d "\n"')