react-in-angular icon indicating copy to clipboard operation
react-in-angular copied to clipboard

Error: React is not defined

Open wenqi73 opened this issue 4 years ago • 4 comments

After run ng build --prod, it throws this error:

image

wenqi73 avatar Dec 15 '20 10:12 wenqi73

Did we get a solution for this?

Any solutions?

PuriaRad avatar Jan 03 '21 09:01 PuriaRad

It seems you need to set aot: false in angular.json.

{
  "projects": {
    "angular-react": { // This is the name of the project
      "architect": {
        "build": {
          "options": {
            "aot": false
          }
        }
      }
    }
  }
}

harjis avatar Feb 01 '21 09:02 harjis

  • import react in angular.json
"assets": [
  {
    "glob": "react.production.min.js",
    "input": "./node_modules/react/umd/",
    "output": "/"
  }
]
  • add a script in index.html
<script src="react.production.min.js"></script>

Or you can import a cdn url.

wenqi73 avatar Feb 03 '21 02:02 wenqi73