react-dnd: REACT 18 + WEBPACK 5: Error: Can't resolve 'process/browser'
Describe the bug
ERROR in ./node_modules/@react-dnd/invariant/dist/index.js 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'
Did you mean 'browser.js'?
BREAKING CHANGE: The request 'process/browser' failed to resolve only because it was resolved as fully specified
Reproduction
mpx create-react-app npm install react-dnd
in /src/index.js add:
import { useDrag } from "react-dnd";
npm run
Expected behavior No Errors in compiling. No need to change the webpack config.
WORKAROUND npm install react-app-rewired -d
create ./config-overrides.js and add:
config.module.rules.unshift({
test: /\.m?js$/,
resolve: {
fullySpecified: false, // disable the behavior
},
});
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 21
- Comments: 15
because react-dnd use process/browser. Solution:
npm i processin webpack config:resolve: { fallback: { 'process/browser': require.resolve('process/browser'), } }@arcsin1 you can modify your Webpack config. If you used
create-react-app, you’ll need something fancy withreact-app-rewiredas described by @ttessarolo.I got away with adding the following to my config:
The
process/browserissue was fixed with the module rule, whereas the issue withjsx-runtime(as mentioned in a number of similar issues) was fixed by adding the resolve alias.You are a damn angel @ttessarolo
i got the same problem
My WORKAROUND
"react-dnd": "^14.0.4", "react-dnd-html5-backend": "^14.0.2"