Running Rspec Tests within RubyMine fails with "Could not find a JavaScript runtime"
I've been using RubyMine for a while but just ran into this error recently after having to re-install Homebrew and re-clone a repo. When I try to run rspec tests from the IDE, I get the error below every time:
/Users/mayaebsworth/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:58:in `autodetect': Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
I can run the same tests from my mac terminal using:
bundle exec rspec <filename>
I think the issue is related to node/nvm and possibly the way my PATH, environment variables, and/or .zshrc file are integrated with my RubyMine, but I'm not sure how to fix it.
I checked in Preferences > Languages & Frameworks > Node.js and NPM. The "Node interpreter" was set to "node - no executable found in $PATH", and I changed it to another option in the dropdown "~/.nvm/versions/node/v16.13.1/bin/node". I also changed the "Package manager" from "npm" to "yarn". But neither of those things worked.
I restarted RubyMine, tried `spring stop`, tried installing node and nvm and yarn from inside the RubyMine terminal, but nothing's worked yet.
Any help would be appreciated! Happy to answer more questions.
请先登录再写评论。
Hello Maya,
That appears to be related to the known problem, could you please check the corresponding issue and proposed workarounds:
https://youtrack.jetbrains.com/issue/IDEABKL-7589/Load-interactive-shell-environment-variables-on-Linux
Hi Olga, thank you for your response! I tried the workarounds but they didn't work for me. I'll include some more detail here in case I'm not doing them correctly.
My environment variables are defined in ~/.zshrc.
I created a ~/.profile file and then pasted everything in my ~/.zshrc into that file. Then I restarted RubyMine and tried to run the tests and got the same error as before. Wasn't sure what "restart X session" meant or if I had to do more than copy & paste.
I looked up how to do this, and then opened up a new terminal window, ran:
Then tried running tests again, got the same error as before. Wasn't sure if I had to add any more arguments to the open command in order to make the environment variables available.
Got it working! I needed to:
Then was able to run tests!
Thank you for your help, Olga!
I'm having the same issue when running tests or ‘rails server’ with a remote interpreter through ssh.
Node was installed on the remote server using NVM. Everything works fine when just logging into the machine through ssh.
But that loads ~/.bashrc as well as ~/.profile, while I get the impression that they way RubyMine executes the tests or rails server ignores these.
Any suggestions?
Ok, I created a symbolic link to the correct node version from /usr/local/bin.
This doesn't feel like the best solution, but it works.
Piet it's good to know that you've found the workaround. That problem still seems to be related to the mentioned issue because you can find similar issues among the linked ones.