REACT 18 + WEBPACK 5: Compiling Errors
See original GitHub issueDescribe the bug Two Compiling Error with REACT 18 and Webpack 5:
ERROR in ./node_modules/@react-dnd/invariant/dist/esm/index.mjs 42:16-23
Module not found: Error: Can't resolve 'process/browser' in '/Users/tommix/DEVELOPMENT/ARES/ares-ui/ares-control-center/node_modules/@react-dnd/invariant/dist/esm'
Did you mean 'browser.js'?
BREAKING CHANGE: The request 'process/browser' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
and:
ERROR in ./node_modules/react-dnd/dist/esm/core/DndProvider.mjs 37:0-51
Module not found: Error: Package path ./jsx-runtime.js is not exported from package /Users/tommix/DEVELOPMENT/ARES/ares-ui/ares-control-center/node_modules/react (see exports field in /Users/tommix/DEVELOPMENT/ARES/ares-ui/ares-control-center/node_modules/react/package.json)
Reproduction
mpx create-react-app npm install react-dnd
in /src/index.js add:
import { useDrag } from "react-dnd";
Steps to reproduce the behavior:
npm start
Expected behavior No Errors in compiling. No need to change the webpack config.
WORKAROUND npm install react-app-rewired -d
create ./config-overrides.js as follow:
const webpack = require("webpack");
module.exports = function override(config, env) {
config.resolve.fallback = {
url: require.resolve("url"),
assert: require.resolve("assert"),
crypto: require.resolve("crypto-browserify"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
os: require.resolve("os-browserify/browser"),
buffer: require.resolve("buffer"),
stream: require.resolve("stream-browserify"),
process: require.resolve("process"),
};
config.plugins.push(
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: ["buffer", "Buffer"],
})
);
config.stats = { ...config.stats, children: true };
// react-dnd
config.module.rules.unshift({
test: /\.m?js$/,
resolve: {
fullySpecified: false, // disable the behaviour
},
});
// react-dnd
config.resolve.alias = {
...config.resolve.alias,
"react/jsx-runtime.js": "react/jsx-runtime",
"react/jsx-dev-runtime.js": "react/jsx-dev-runtime",
};
return config;
};
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Error when install min.io with reactjs >18 and webpack > 5.xx
the only solution now is to resolve the dependencies manually : check this out https://github.com/minio/minio-js/issues/1053.
Read more >Webpack 5 errors | ImmutableX Documentation
The reason for this error is that create-react-app uses a version of webpack greater than 5, which, unlike versions < 5, does not...
Read more >React v18.0 – React Blog
React 18 is now available on npm! In our last post, we shared step-by-step instructions for upgrading your app to React 18.
Read more >I am unable to start or build the application in the course React ...
Html Webpack Plugin: Error: Child compilation failed: Module. ... [course-directory]/[html-webpack-plugin]/lib/child-compiler.js:169:18.
Read more >Issues compiling typescript project with Typescript 4, React
p>I was previously compiling mdb-react-ui-kit (sourced from npm) with ... React 18, Webpack 5 and MDB react ui kit essential package.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is it possible to merge this as a permanent fix or does it potentially break something else?
The cause is probably here.