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

Compile error - module not found - cannot resolve 'react/jsx-runtime'

Open knuula opened this issue 1 year ago • 13 comments

Describe the bug

ERROR in ./node_modules/@react-pdf/renderer/lib/react-pdf.browser.js 15:0-40 Module not found: Error: Can't resolve 'react/jsx-runtime' in 'D:\client\node_modules@react-pdf\renderer\lib' 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.

image

To Reproduce

I just updated a few packages and suddenly got this error whenever I do npm run start or npm run build in my react project.

Screenshots If applicable, add screenshots to help explain your problem.

I think it has something to do with this below. This is from @react-pdf/renderer/lib/react-pdf.browser.cjs

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _extends = require('@babel/runtime/helpers/extends'); var primitives = require('@react-pdf/primitives'); var queue = require('queue'); var require$$1 = require('react'); var _regeneratorRuntime = require('@babel/runtime/helpers/regeneratorRuntime'); var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator'); var FontStore = require('@react-pdf/font'); var renderPDF = require('@react-pdf/render'); var PDFDocument = require('@react-pdf/pdfkit'); var layoutDocument = require('@react-pdf/layout'); var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose'); var require$$0 = require('object-assign'); var scheduler = require('scheduler'); var jsxRuntime = require('react/jsx-runtime');

Desktop (please complete the following information):

I experienced the issue with the following versions of react-pdf/renderer:

3.1.5 3.4.0

knuula avatar Mar 24 '24 17:03 knuula

Having the same issue.

calebloveshockey avatar Apr 02 '24 10:04 calebloveshockey

Me too

rohmansca avatar Apr 15 '24 11:04 rohmansca

Add the following to your webpack config.

alias: {
      // existing
      'react/jsx-runtime': 'react/jsx-runtime.js',
},

After that, run install and build commands again.

abhinavtalentinc avatar Apr 16 '24 13:04 abhinavtalentinc

Hi @abhinavtalentinc, where I can find the webpack config file?

fabianEspn404 avatar Apr 19 '24 04:04 fabianEspn404

Got the same error. But i have worked with v3.1.12. So i downgraded to it.

sankaSanjeeva avatar Apr 19 '24 08:04 sankaSanjeeva

Upgrading react version from 16 to 17 helped

https://stackoverflow.com/questions/65527359/got-cant-resolve-react-jsx-runtime-error-while-use-try-to-create-the-shared-c

cyber-gh avatar Apr 26 '24 17:04 cyber-gh

Upgrading react version from 16 to 17 helped

https://stackoverflow.com/questions/65527359/got-cant-resolve-react-jsx-runtime-error-while-use-try-to-create-the-shared-c

Not working for react v17 as well

Avni1802 avatar May 15 '24 13:05 Avni1802

So, except webpack, have anyother way to reslove the problem?😭

slatejack avatar Jun 04 '24 02:06 slatejack

I've got another problem, I updated my @react-pdf/renderer to 3.4.4 and added this to my webpack config alias: { 'react/jsx-runtime': 'react/jsx-runtime.js', }, but my app is not render at all Screenshot 2024-06-04 at 13 31 43

stevenKirill avatar Jun 04 '24 10:06 stevenKirill

Does anybody know how can I make icon only with border in react-pdf-render ? Coz it's always fill, even if I pass props fill="none" to Svg component Screenshot 2024-06-04 at 13 51 47 Screenshot 2024-06-04 at 13 56 49

stevenKirill avatar Jun 04 '24 10:06 stevenKirill

I've got another problem, I updated my @react-pdf/renderer to 3.4.4 and added this to my webpack config alias: { 'react/jsx-runtime': 'react/jsx-runtime.js', }, but my app is not render at all Screenshot 2024-06-04 at 13 31 43

https://github.com/wojtekmaj/react-pdf/wiki/Upgrade-guide-from-version-8.x-to-9.x#webpack-based-applications-may-require-a-workaround @stevenKirill try this

NorthwesternDirector avatar Jun 14 '24 09:06 NorthwesternDirector

alias: { // existing 'react/jsx-runtime': 'react/jsx-runtime.js', },

How would I do this if I'm using vite instead of webpack?

zergcore avatar Jul 03 '24 15:07 zergcore

I'm with problem in npm run build just existing webpack.config with param 'react/jsx-runtime':

C:\frontend>npm run build

[email protected] build react-scripts build

Creating an optimized production build... Failed to compile.

Module not found: Error: Can't resolve 'react/jsx-runtime' in 'C:\frontend\node_modules\react-pdf\dist\esm' 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.

As resolve this problems? Please, help-me.

onyxadm avatar Sep 16 '24 16:09 onyxadm

Add the following to your webpack config.

alias: {
      // existing
      'react/jsx-runtime': 'react/jsx-runtime.js',
},

After that, run install and build commands again.

Just to make it clear its under resolve

resolve: {
	alias: {
		// existing
		'react/jsx-runtime': 'react/jsx-runtime.js',
	},
},

chenop avatar Jan 04 '25 10:01 chenop

I fixed it with:

	module: {
		rules: [
			{
				test: /\.m?js$/,
				resolve: {
				  fullySpecified: false,
				},
			},

1Jesper1 avatar Jan 29 '25 10:01 1Jesper1

Unrelated to this lib

diegomura avatar Mar 05 '25 00:03 diegomura