how to run node / babel script directly in command line?
node ./node_modules/babel-cli/bin/babel-node.js --presets env app.js
You can execute npm package binaries with npx
.
Because Babel 7 always resolves plugins and presets relative to local project folder, you will have to install @babel/preset-env
locally into the project.
npm i -D @babel/preset-env
After that the babel-node
can be run with npx
without installation into the project:
npx -p @babel/core -p @babel/node babel-node --presets @babel/preset-env app.js
If you install @babel/node
into the project, npx
will prefer project-local version.
In case of Babel 6 the command below can be used:
npx babel-node --presets env app.js
Great gugley mugleys! This was way harder than it should have been.
See here for docs. TLDR;
Babel > version 7.0 has to go in your package.json
to run from command line.
npm install --save-dev @babel/core @babel/cli @babel/preset-env @babel/node
npx babel-node --presets @babel/preset-env imports/test.js