Skip to content
Advertisement

unable to use babel to run file

I’m trying to get more familiar with modern javascript and am following a tutorial. Early setup includes running a file from another file. I have a server.js file with a simple ‘import ‘./config’; command. As a test that repo setup is correct, I should be able to run ‘babel server.js’. But I keep returning the error shown below. How do I troubleshoot so that I can successfully run babel commands?

JavaScript

Things I’ve tried so far

  • as per tutorial, tried updating my bash_profile w/ ‘export PATH=$PATH:./node_modules/.bin’
  • tried setting it in global PATH variable
  • setting all devDependencies in package.json file that mention @babel to consistent version.
  • After updating package.json file, new error is below:
JavaScript

When I run babel –version, it returns ‘7.19.3 (@babel/core 7.19.3)’ matching package.json file.

contents of files:

content.js

JavaScript

server.js

JavaScript

package.json

JavaScript

webpack.config.js

JavaScript

babel.config.js

JavaScript

A picture of my repo file structure for reference: file structure

Advertisement

Answer

please do the following step

  1. add “type”: “module” in package.json

    { “name”: “modern_javascript_app_example”, “version”: “1.0.0”, “description”: “Learning …”, “main”: “index.js”, “type”: “module”, “scripts”: {

  2. and use import ‘./content.js’; not import ‘./config’; in serer.js file

Advertisement