G
G
GunAlv2021-02-15 11:40:43
React
GunAlv, 2021-02-15 11:40:43

How to properly import ReactDOM?

Using the BundleAnalyzerPlugin, the bold react-dom.development (imported in the app.js entry file) gets into the production code, while it is possible to import the corresponding code assembly. How to do it?
import ReactDOM from 'react-dom';
602a337bda6c5207290052.png602a338939fbf397762238.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GunAlv, 2021-02-15
@GunAlv

The problem turned out to be simple.
Quite node_modules/react-dom/index.jsexpectedly, there is a check for build mode:

if (process.env.NODE_ENV === 'production') {
  // DCE check should happen before ReactDOM bundle executes so that
  // DevTools can report bad minification during injection.
  checkDCE();
  module.exports = require('./cjs/react-dom.production.min.js');
} else {
  module.exports = require('./cjs/react-dom.development.js');
}

The problem was that in directories other than the config directories (the one where the settings for webpack are located), the variable process.env.NODE_ENV was not defined, perhaps because the mode was set only in package.json:
"build": "cross-env NODE_ENV=production webpack --config ./config/base.config.js",

Solved by adding a plugin
new webpack.DefinePlugin({
  'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
});
into assembly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question