Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

336
Vistas
ReferenceError: React is not defined with Parcel Bundler

I am following this Article to bundle my react app as a single js file that can be embedded as a widget into any website

Here is a redacted version of my package.json file showcasing the build scripts

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "build:widget": "parcel build src/index.js --no-source-maps -d widget" //This
  }

So, on running yarn build:widget, I want parcel to build the entire App into a single index.js file that I can embed in a regular html file.

The build worked, but the only issue now is that I am getting the error ReferenceError: React is not defined after referencing the output index.js file inside my index.html file as shown below

<body>
    <p>Hello World</p>
    <div id="widget-section"></div>
</body>
<link href="../index.css" rel="stylesheet" />
<script src="../index.js"></script> //ReferenceError: React is not defined gets thrown here

Is there a better work around to this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Even if your JavaScript does not explicitly call React i.e. import React from "react", you still need to add this import if you are using JSX. This is due to your JSX transpiler inlining JSX as React.createElement calls.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda