react-data-grid icon indicating copy to clipboard operation
react-data-grid copied to clipboard

Module not found: Error: can't resolve 'react/jsx-runtime'

Open jfideler opened this issue 4 years ago • 12 comments

Describe the bug

Right out of the box:

Compiled with problems: ERROR in ./node_modules/react-data-grid/lib/bundle.js 3:0-56

Module not found: Error: Can't resolve 'react/jsx-runtime' in '...\node_modules\react-data-grid\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.

To Reproduce

  1. npx create-react-app my-app --template typescript
  2. npm install
  3. npm run start
  4. npm install react-data-grid
  5. create a new page and add 'import DataGrid, { SelectColumn } from 'react-data-grid';'
  6. Add a simple reference in the code such as 'my columns=[SelectColumn, {key: 'name'}];

Link to code example: see line 15 in Hompage.tsx

Expected behavior

Referencing SelectColumn in typescript code should not cause a compile error.

Environment

windows 10 [email protected] [email protected]

-"react": "^17.0.2", -"react-data-grid": "^7.0.0-beta.7", -"react-dom": "^17.0.2",

Additional context

It seems that we can solve the problem if we change the version from "react-data-grid": "^7.0.0-beta.7", to "react-data-grid": "7.0.0-canary.30", (without the '^') in all of these places: -package.json -package-lock.json -node-modules/react-data-grid/package.json

Should we really have to do this? or have we done something wrong?

jfideler avatar Jan 14 '22 15:01 jfideler

same issue: image

Module not found: Error: Can't resolve 'react/jsx-runtime' in 'C:\Users\o\github\vsedit\node_modules\.pnpm\[email protected][email protected][email protected]\node_modules\react-data-grid\lib

image

wisehackermonkey avatar Jan 17 '22 00:01 wisehackermonkey

@jfideler Thank you!

I too am experiencing this as described. Following @jfideler lead ...

  1. In package.json change the version of "react-data-grid": "^7.0.0-beta.7", to "react-data-grid": "7.0.0-canary.30",
  2. Delete the package-lock.json file
  3. Delete the entire node_modules directory
  4. Run npm install to recreate the package-lock.json and node_modules directory are rebuilt accordingly

This is a valid work around for my instance.

jamrsim avatar Jan 18 '22 15:01 jamrsim

for me another solution works

downgrading react-scripts from v5 to v4 so minimal dependencies in my case:

  "dependencies": {
    "@types/react": "^17.0.38",
    "@types/react-dom": "^17.0.11",
    "react": "^17.0.2",
    "react-data-grid": "^7.0.0-beta.7",
    "react-dom": "^17.0.2",
    "react-scripts": "^4.0.3",
    "typescript": "^4.5.4"
}

working great without downgrading react or data-grid

using

    "@types/react": "^17.0.38",
    "@types/react-dom": "^17.0.11",
    "react": "^17.0.2",
    "react-data-grid": "^7.0.0-beta.7",
    "react-dom": "^17.0.2",
    "react-scripts": "^5.0.0",
    "typescript": "^4.5.4"
  }

results in Can't resolve 'react/jsx-runtime'error

phibar avatar Jan 20 '22 05:01 phibar

setting jsx: react-jsx in tsconfig.json

and using alias in webpack.config solves for me.

  resolve: {
      alias: {
          "react/jsx-dev-runtime": "react/jsx-dev-runtime.js",
          "react/jsx-runtime": "react/jsx-runtime.js",
      }
  },

Berkays avatar Jan 28 '22 13:01 Berkays

Seeing the same issue in version 7.0.0-beta.8. The solution suggested by @Berkays worked for me as well.

peetjvv avatar Feb 03 '22 14:02 peetjvv

@Berkays' solution doesn't work with NextJS -- Next requires using jsx: preserve. Currently, the only workaround seems to be using the react + react-dom 18 release candidate (react@next, react-dom@next), but this isn't great for a production app currently.

Chrysippus avatar Feb 09 '22 14:02 Chrysippus

I don't want to downgrade react-scripts from 5 to 4 :/

yairEO avatar Feb 21 '22 21:02 yairEO

@yairEO Same. This is still happening, is there any updates on that issue?

farukbigez avatar Mar 15 '22 11:03 farukbigez

Our answer was to ditch this flaming POS and use react-table. What a relief!

jfideler avatar Mar 15 '22 11:03 jfideler

Please check https://github.com/facebook/react/issues/20235 and a workaround

amanmahajan7 avatar Mar 18 '22 02:03 amanmahajan7

The solution for NextJS is to use the nextJs transpile module plugin and update your nextjs config file, look it up. There are a couple packages that have this bug.

noah-ellman avatar Apr 21 '22 07:04 noah-ellman

Here is a solution that work for me.

Our codebase was running on react 17

Upgrading those package in package.json fixed the issue "react": "^18.1.0", "react-dom": "^18.1.0", "react-is": "^18.1.0",

Too, i'm using the last react-data-grid version (now it is "react-data-grid": "7.0.0-beta.12")

relyada avatar May 03 '22 13:05 relyada