0

Got this when loading a component: ReferenceError: React is not defined

Tried this solution here: Uncaught ReferenceError: React is not defined

added following to webpack.config.json

externals: {'react': 'React' },

but then I got following error. So what is wrong?

external "React":1 Uncaught ReferenceError: React is not defined
    at 63804 (external "React":1:18)
    at n (bootstrap:19:32)
    at shortcode32.js?ver=2.0.37:2:317202
    at shortcode32.js?ver=2.0.37:2:385167

What files / code should I show to provide you with more info?


Error is raised here:

react-dom.production.min.js:194 ReferenceError: React is not defined
    at R (LoginAndRegistrationL.tsx:2:2)
    at Yi (react-dom.production.min.js:145:98)

in LoginAndRegistrationL.tsx funny, I removed everything from LoginAndRegistrationL.tsx, only a raw componenet I left:

export default function LoginAndRegistrationL(props: {}) {
    return <div></div>
}

Why it raise the error?

This componenet will be visible when a button press happens. Why other component does not raise "React" error, but this yes.

  • did you try adding `externals: { 'react': 'React' },` in **webpack.config.json** – monim Jul 21 '22 at 12:27
  • yes, I tried it –  Jul 21 '22 at 12:34
  • I do not know it matters, but prettier chenges key from `'react'` to `react`. And I also tried change value from `'React'` to `'react'`. Did not help. –  Jul 21 '22 at 12:41
  • import React from 'react'; check you imported react or not – Rohit Rana Jul 21 '22 at 12:42
  • and if you are using babel then { "presets": [ "@babel/preset-env", ["@babel/preset-react", {"runtime": "automatic"}] ] } – Rohit Rana Jul 21 '22 at 12:43
  • @RohitRana I am not sure I am using babel or not. babel lines are in package.json, but 'before' this error was not raised. This babel setting need to add for certain file type? –  Jul 21 '22 at 12:56

0 Answers0