Sharun Sharun - 1 month ago 15
React JSX Question

babel react issues finding modules

I have a small react jsx file that needs to be compiled to js.

I install babel and the presets like so in the directory with the js file

npm -g install babel-cli

npm install babel-preset-es2015 babel-preset-react


My script does this

babel --presets es2015,react input.js -o output.js


Everything works.

Reboot the machine and re-run the build. It fails.

Each time I reinstall babel and the presets to get it to work.

I am not a js dev and looking up the similar questions list and a google search for this issue returns 25 different ways of "fixing" the issue. This seems like a basic task, why is there so much noise around it and what is the right way to add this to a larger non-javascript build process .

Answer

You have to install the presets globally.

Do this

  1. Create a new folder and move you input.js to that folder
  2. Do npm init
  3. Do npm i babel without -g
  4. Do npm install babel-preset-es2015 babel-preset-react
  5. Open the console at that location
  6. Run ./node_mudules/.bin/babel --presets es2015,react input.js -o output.js
Comments