0

I'm following the React setup guide for setting up React for the first time. However, I've added async/await to my code. When the preprocessor - npx babel runs, the output file looks like:

Uncaught SyntaxError

and the browser console is giving me the error:

Uncaught SyntaxError: Unexpected identifier

for the import.

I've checked that babel-runtime is in my node-modules.

My package.json dependencies looks like:

  "dependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-react-app": "^3.1.2"
  }
Matt McCormick
  • 13,041
  • 22
  • 75
  • 83

1 Answers1

0

first of all, remove the old dependencies

npm uninstall -D babel-cli babel-preset-react-app babel-runtime

then add the latest dependencies

npm i -D @babel/core @babel/preset-react @babel/cli babel-runtime

after the latest dependencies installed package.json looks like

"devDependencies": {
    ...
    "@babel/cli": "^7.13.14",
    "@babel/core": "^7.13.8",
    "@babel/preset-env": "^7.13.9",
    "@babel/preset-react": "^7.13.13",
    "babel-runtime": "^7.0.0-beta.3",
    ...

after fixing this you might face an issue(regeneratorRuntime is not defined) then you need to add the runtime.js script in your HTML file

https://github.com/facebook/regenerator/blob/master/packages/runtime/runtime.js

Sanjay Nishad
  • 1,537
  • 14
  • 26