Tachyon80
Tachyon80

Reputation: 157

Setting Up Babel for JSX on Mac

Trying to set up Babel for React/JSX.

I've set up a package.json file and used NPM to install babel-cli and babel-preset-react.

~~from my package.json file~~

   "babel": {
    "presets": [
      "react"
    ]
    },
"devDependencies": {
  "@babel/cli": "^7.2.3",
  "@babel/core": "^7.2.2",
  "@babel/preset-env": "^7.3.1",
  "@babel/preset-react": "^7.0.0",
  "babel-cli": "^6.26.0",
  "babel-preset-react": "^6.24.1"
},

"dependencies": { "@babel/polyfill": "^7.2.5" }

I should be able to type (at the command line):

$ babel --version

and get a result. Instead, I get:

-bash: babel: command not found

Any ideas how to fix this? I want to start compiling ES6 JavaScript and JSX to regular JavaScript.

Upvotes: 0

Views: 1061

Answers (1)

Lex
Lex

Reputation: 5014

You'll need to install babel globally for it to become available as a bash command. npm install -g babel.

Alternatively to installing it globally the executable will be in the node_modules path. ./node_modules/.bin/babel

If you're using it apart of webpack or some other build tool your config should be OK.

Upvotes: 1

Related Questions