Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to run babel-node via shell command

I am trying to use babel-node to run files in my node project.

I am able to get them running if I set up an npm script, such as:

"scripts": {
    "start": "babel-node src/index.js"
  },

However, if I try to run it via the cli, I get the error: zsh: command not found: babel-node.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve already tried installing babel-node both globally, and as a dev-dependency, via:

npm i -g @babel/node @babel/cli

But this hasn’t worked for me.

Does anyone know why the shell command doesn’t work?

>Solution :

per https://babeljs.io/docs/babel-node

Compile and run test.js.

Shell

npx babel-node test

so you should update your script to

"scripts": {
    "start": "npx babel-node src/index.js"
  },

And you should be able to lose the /index.js part, simplifying to

"scripts": {
    "start": "npx babel-node src"
  },
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading