Webpacker: Node version checker doesn't recognize NodeJS when using NVM.

Created on 22 Jan 2018  路  8Comments  路  Source: rails/webpacker

https://github.com/rails/webpacker/blob/18a50dcce2b6a48d85c5e2a5e8a1634d2c22a2ac/lib/tasks/webpacker/check_node.rake#L5-L6

This breaks on deploy saying that neither node nor nodejs exists. I've double checked on our server and our deploy user DOES have access to the node command (via NVM) in the project directory.

Is there some setting we can be adding to force webpacker to use NVM properly?

Any other insights?

Thanks!

Most helpful comment

For those that run into this issue later, I found that in my case we were running rails under Apache, so the NVM installed Node wasn't accessible to the user that Apache was running as. Silly mistake :)

All 8 comments

@tylercrocker Seems more like an environment/node/nvm issue compared to a webpacker one. I would assume node_version = node -v || nodejs -v is just running that command in the same terminal session as the rake task.

@aleccool213 It does use the same terminal session, but the problem is that the node/nodejs call needs to be prefixed with some ENV stuff for NVM. We've created this .sh file to configure NVM with the contents:

#!/bin/bash -e
source "$HOME/.nvm/nvm.sh"
nvm use $NODE_VERSION
exec "$@"

And then for any scripts we're running in our deploy that need to utilize node commands we prefix them with that shell script.

The problem we're running into is that webpacker is doing a raw call to node/nodejs and has no way for us to prefix that call with our NVM shell script.

This "prefixing" practice is how we normally handle running deploy scripts for rbenv. If this is not how NVM should be handled and there is some other practice we're not aware of we'd love to hear it! We're still kind of new to using Node :(

@tylercrocker Interesting. The fact that you have to prefix every node script with something that activates nvm is not really the point of nvm :) Once activated in a terminal session, nvm should have aliased all node calls correctly.

@tylercrocker Is this still an issue? The check is pretty standard and as long as node executable is globally available the check should pass (tools like yarn requires it to be in path). Prefixing every call sounds pretty tedious. Is it not possible to install a node version globally on server in your case?

We figured it out. We apparently had some script in our .bashrc file that was breaking everything. Kinda amazing we haven't run into any issues with that in the past, hah.

For those that run into this issue later, I found that in my case we were running rails under Apache, so the NVM installed Node wasn't accessible to the user that Apache was running as. Silly mistake :)

We figured it out. We apparently had some script in our .bashrc file that was breaking everything. Kinda amazing we haven't run into any issues with that in the past, hah.

Yes, that was my issue too.. commenting out [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
fixed the issue.

@tylercrocker I have spent like 5 hours on this and your comment was what finally prompted me to check my ~/.bashrc file. Thank you very much sir!

Was this page helpful?
0 / 5 - 0 ratings