How to package your React Component for distribution via NPM
Suprada Urval
1K9

Hello @Suprada Urval, When I exclude reactjs from the bundle of my components using webpack externals I’m getting this error “Super expression must either be null or a function, not undefined”.

I have a Vendors file that is loaded in parallel with the component bundles. This allows to share the Reactjs between all components, reducing the size of the bundles, and for other performance reasons.

The Vendors file has a script that creates window.vendors.React with the necessary code, but the error occurs when some component bundles arrive before the Vendors file.

In my webpack.config.js:
externals: {
react: 'window.vendors.React',
'react-dom': 'window.vendors.ReactDOM',
 }

One option is to load the Vendors file, check that the Vendors file has loaded, and then load the components. To do this though, would create delays in loading the components. I want to find a solution that has no impact on the load time of the components.

Regards