Joey Yi Zhao
Joey Yi Zhao

Reputation: 42546

Get `env: node: No such file or directory` error when run `babel` in Intellij

I am using Intellij ultimate 2017.3 and installed nodejs plugin on it. My nodejs project requires babel to do the translation work from es5 to es6. In order to make Intellij to be able to debug my nodejs process, I added a file watcher plugin to listen on the source code changes. Once a file is changed, it will run below command to translate the code:

babel ./src --out-dir ./lib --source-maps

this command works fine from my OS but I get below error in Intellij:

env: node: No such file or directory

Process finished with exit code 127

I am using MacOS 10.13.1 and my node is managed by nvm which is at the v8.9.1. Babel is 6.26.0. Is there any problem in Intellij to call babel command? Or is it a babel or node environment problem on my OS?

Upvotes: 7

Views: 8566

Answers (5)

Paulo Rodrigues
Paulo Rodrigues

Reputation: 33

I am searching for this solution for many hours, now I figure it out the solution. I resolved the issue by adding in the "Environment variables" on the file watchers:

:/opt/homebrew/bin/

In my case the complete line now is:

PATH=/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/opt/homebrew/bin/

/opt/homebrew/bin/ is where my node and nvm are. You can user "which node" to discover where your is (I am using Macosx Sonoma).

I hope I can help someone with it.

Upvotes: 0

Code-Apprentice
Code-Apprentice

Reputation: 83537

In my case with a similar issue, I had installed nvm and node. I only needed to reboot my computer for the changes to PATH to be reflected in the X environment.

Upvotes: 0

Arseniy-II
Arseniy-II

Reputation: 9177

It is a $PATH issue. You can set $PATH variable when configure file watcher.

  1. type in to your terminal echo $PATH
  2. copy result, it should be something like this /Applications/bin:/usr/local/bin
  3. Go to Preferences/Tools/File Watchers
  4. Select your file watcher, press enter or click "edit"
  5. Click "Other Options" and "Environment variables"
  6. Click "+"
  7. Type "PATH" in "Name" column
  8. Paste copied text in "Value" column
  9. List item
  10. Press ok

enter image description here

Link to original solution

Upvotes: 16

Andreas Berger
Andreas Berger

Reputation: 883

I had the problem with IntelliJ in combination with nvm. The problem is that FileWatcher doesn't seem to use bash. My solution was to add the following lines to the end of ~/.profile:

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

Upvotes: 2

lena
lena

Reputation: 93778

Must be a $PATH issue. Can you check if the problem persist when running IDEA from terminal (open -a /Applications/idea.app )?

on MacOSX the environment variables differ between GUI applications and within the terminal. Terminal environment is only available to applications started from terminal. To solve this problem, IDEA tries to load terminal environment by executing the following command on startup:

<your shell> -l -i -c '/Applications/idea.app/bin/printenv.py'

Seems this command can't retrieve all needed stuff in your case - thus the issue.

Some links you may find useful: http://apple.stackexchange.com/questions/106355/setting-the-system-wide-path-environment-variable-in-mavericks, https://devnet.jetbrains.com/docs/DOC-1160#comment-2801, http://apple.stackexchange.com/questions/51677/how-to-set-path-for-finder-launched-applications.. The problem is that the way to define system-wide environment variables on Mac changes from one version to another (even minor system updates may break your environment)

Upvotes: 4

Related Questions