question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

REACT 18 + WEBPACK 5: Compiling Errors

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Reactions:2
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
vockocommented, Apr 4, 2022

This can easily be fixed by patching node_modules/react-dnd/dist/esm/core/DndProvider.mjs. Update the first line to remove the .js extension.

-import { jsx as _jsx } from "react/jsx-runtime.js";
+import { jsx as _jsx } from "react/jsx-runtime";

Is it possible to merge this as a permanent fix or does it potentially break something else?

5reactions
bug-braincommented, Apr 2, 2022

The cause is probably here.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found