Cannot find module `.../jsx-runtime`

See original GitHub issue

Describe the bug

I have a library that depends on another library. Both using vite to build with react@17, TypeScript, pnpm, and in ESM.

The build works fine, but vitest failed with:

Error: Cannot find module 'D:\code\justland\just-web-react\libraries\react\node_modules\react\jsx-runtime' imported from D:\code\justland\just-web-react\libraries\react\dist\just-web-react.js
Did you mean to import react/node_modules/.pnpm/react@17.0.2/node_modules/react/jsx-runtime.js?

Reproduction

Since it involves one library referencing another, it will take some effort to come up with a minimal repro.

For the time being, here is the code:

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
    Memory: 31.94 GB / 63.92 GB
  Binaries:
    Node: 14.20.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.17 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.819.0), Chromium (108.0.1462.42)
    Internet Explorer: 11.0.22621.1

Used Package Manager

pnpm

Validations

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sheremet-vacommented, Dec 8, 2022

Your files need to be processed by Vitest (they are externalised in your case). Add this to your vite.config.ts:

export default {
  test: {
    deps: {
      inline: [/@just-web/, /just-web-react/]
    },
  },
}

I was also able to fix the issue by adding .js extension to import, since jsx-runtime is not specified in react’s exports field (otherwise, it’s required by ESM spec). This would actually be faster than inlining dependency.

0reactions
geekactcommented, Dec 19, 2022

Yeah, I’m using React 17 which does not have the exports fields at all.

Maybe I can file a PR to React to fix that in 17 (17.0.3)

Have a look at this issue and it’ll never be fixed for react 16 and 17 https://github.com/facebook/react/issues/20235

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught Error: Cannot find module 'react/jsx-runtime'
This solution resolved my issue. I found it over here. 👇️ with NPM. npm install react@latest react-dom@latest ...
Read more >
Cannot find module 'react/jsx-runtime' · Issue #2119 - GitHub
It means that it doesn't find react/jsx-runtime module as if you would have an older version installed. Please always try to share a...
Read more >
Module not found: Can't resolve 'react/jsx-runtime' | bobbyhadz
To solve the error "Module not found: Error: Can't resolve 'react/jsx-runtime'", make sure to update the react package by opening your terminal in...
Read more >
cannot find module '@emotion/react/jsx-runtime' or its ...
If you're still getting the "Cannot find module 'react/jsx-runtime' or its corresponding type declarations" error, open your package.json file and make sure ......
Read more >
[Solved]-Uncaught Error: Cannot find module 'react/jsx-runtime'
[Solved]-Uncaught Error: Cannot find module 'react/jsx-runtime'-Reactjs ... So my setup actually was working. There was somehow a glitch in the symlink. I as...
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