Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Babel Automatic runtime for react doesnt working properly . Still getting Uncaught ReferenceError: React is not defined

according to new versions of React, we shouldn't always import React from 'react' But I still have an error Uncaught ReferenceError: React is not defined

.babelrc (Switching an order of presets doesnt help, removing some of presets too)

{
  "presets": [
    [
      "@babel/preset-react",
      {
        "runtime": "automatic"
      }
    ],
    "@babel/env",
    "@babel/preset-typescript"
  ]
}

pakage.json

    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "typescript": "^4.6.3",
    "@babel/core": "^7.17.8",
    "@babel/node": "^7.16.8",
    "@babel/preset-env": "^7.16.11",
    "@babel/preset-react": "^7.16.7",
    "@babel/preset-typescript": "^7.16.7",
    "@types/react": "^17.0.43",
    "@types/react-dom": "^17.0.14",
    "babel-loader": "^8.2.4",
like image 203
Vasya Krenta vkrenta Avatar asked Apr 16 '26 09:04

Vasya Krenta vkrenta


1 Answers

For anyone stupid like me, Babel silently ignored my babel config file because a config already existed in the package.json file. Make sure you only have one config source, I guess.

like image 114
Tom Avatar answered Apr 17 '26 22:04

Tom