Reputation: 7307
I'm attempting to do the following babel installation.
$ mkdir babel-test
$ cd babel-test
$ npm init
$ npm install --save-dev babel-cli
At this point, I've got the following tree.
├── package.json
├── node_modules
│ ├── babel-cli
│ ├── etc...
And at this point, I think I'm good to go. But I get this error.
$ babel
=> -bash: /usr/local/bin/babel: No such file or directory
These are the contents of my package.json
{
"name": "babel-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.4.0"
}
}
What am I doing wrong? Of course, it looks like it isn't looking in the correct directory for babel.
Upvotes: 2
Views: 1709
Reputation: 1373
If you're going to install it locally to your project, you'll have to reference it via the absolute path in the node_modules directory:
./node_modules/.bin/babel
Check out the usage section in the docs. It gives an example of setting up an npm script which might be your best option.
https://babeljs.io/docs/setup/#babel_cli
Alternatively, you could use some build tool (such as grunt or gulp) to set up a service that watches the files you want to transpire for changes and have the traspile occur on file change events.
Upvotes: 5