customize-cra icon indicating copy to clipboard operation
customize-cra copied to clipboard

addWebpackExternals: react is not defined

Open xxxsf opened this issue 3 years ago • 1 comments

Problem:

when i use addWebpackExternals(deps):

addWebpackExternals({
  react: "React",
  "react-dom": "ReactDom"
});

browser occur following error:

external "react":1 Uncaught ReferenceError: react is not defined
    at Object.react (external "react":1:1)
    at __webpack_require__ (bootstrap:789:1)
    at fn (bootstrap:150:1)
    at Module../src/index.tsx (index.less?1e97:45:1)
    at __webpack_require__ (bootstrap:789:1)
    at fn (bootstrap:150:1)
    at Object.1 (web3.js:67:1)
    at __webpack_require__ (bootstrap:789:1)
    at checkDeferredModules (bootstrap:45:1)
    at Array.webpackJsonpCallback [as push] (bootstrap:32:1)
    at main~._e.chunk.js:1:69

how to solve this problem?

xxxsf avatar Apr 20 '22 02:04 xxxsf

Any solution to this problem? Only temporary solution I found was to add this 2 lines at the top of index.js

import React from 'react'; window.React = React;

Fixes webpack transpile when using custom loader like esbuild-loader, alterative for webpack plugin ProvidePlugin({React: 'react'})

davidbejarcaceres avatar May 04 '22 09:05 davidbejarcaceres

You should introduce React in a CDN manner, otherwise there will be no React during construction

promiseLC avatar Aug 31 '23 15:08 promiseLC