react-share icon indicating copy to clipboard operation
react-share copied to clipboard

Module not found: Error: Can't resolve 'react/jsx-runtime' in 'node_modules/react-share/dist'

Open himavan opened this issue 1 year ago • 10 comments

Hey the following is the error

Module not found: Error: Can't resolve 'react/jsx-runtime' in '/node_modules/react-share/dist'
Did you mean 'jsx-runtime.js'?
BREAKING CHANGE: The request 'react/jsx-runtime' 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.

himavan avatar Nov 30 '23 12:11 himavan

Hello! Are you on React 18?

nygardk avatar Nov 30 '23 13:11 nygardk

Hey! I'm react 17.0.2

himavan avatar Dec 01 '23 06:12 himavan

Hello, we have the same issue. On 17.0.2 as well. It seems to only happen when running on Windows, not on Mac or Ubuntu.

mmacarth avatar Dec 06 '23 17:12 mmacarth

For others, fyi. We use webpack and we'd solved the issue by adding the following rule:

           {
              test: /\.js$/,
              include: /node_modules\/react-share/,
              resolve: {
                fullySpecified: false,
              },
            },

This matches .js files in node_modules/react-share and sets fullySpecified to false as there's no extension on the import from jsx-runtime in react-share.

On windows, the include regex wasn't working as it includes a "/". Instead using:

     include: path.resolve('node_modules', 'react-share'),

does match the windows formatting for path and the build succeeds.

mmacarth avatar Dec 06 '23 22:12 mmacarth

Hello is there any workaround or fix for this?

loishobe avatar Jan 15 '24 15:01 loishobe

So sad :( Moving to other library until this is solved...

monecchi avatar Mar 06 '24 16:03 monecchi

same happening for us

sudhanshutech avatar Mar 08 '24 06:03 sudhanshutech

bummer

zachandblue avatar May 08 '24 20:05 zachandblue

It was creating same issue on vitest.

Fix was simply adding this package as inline, so that vite process the package:

In vite.config.js:

export default defineConfig({
  test: {
    globals: true,
    environment: "jsdom",
    // vite apply necessary aliases to react-share
    deps: { inline: ["react-share"] }
  }
});

kerematam avatar Aug 15 '24 11:08 kerematam