Using Babel with Atom

I was unable to use Script, a script runner for Atom, when using the language-babel package that autocompletes ES2016 and JSX syntax. I kept getting an error that said:

“Unable to run
Did you start Atom from the command line?
 atom .”

For the longest time I was skipping this and switching the language from Babel to JavaScript in order to run the script then switching back to get the autocomplete and syntax highlighing. This was getting tiresome switching back and forth so I had to figure out what was going on.

Atom wants you to launch into the project from your terminal using atom . when you are in directory of your project. Doing this allows Atom to use the environment that was available to you when you were in the directory that you launched Atom from. Okay, so figuring out that got me closer but it still wasn’t working.

Next thing I needed to do was figure out why I wasn’t able to reach babel-node. I knew that babel-node was available to me if I used ./node_modules/.bin/babel-node but I needed to get it to work using babel-node. The way I was able to achieve this was to run npm install -g babel-cli. This made babel-node available for me to use in any directory. Now I am able to autocomplete ES2016 and JSX syntax and run scripts and see the results in Atom with no issues!