Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin:vite:import-analysis] Failed to resolve import "react/jsx-dev-runtime" from "src/main.tsx". Does the file exist? #391

Closed
7 tasks done
mrdulin opened this issue Nov 28, 2024 · 1 comment

Comments

@mrdulin
Copy link

mrdulin commented Nov 28, 2024

Describe the bug

Try to use vite with react 16.10.0, got the error when start the dev server

Reproduction

https://stackblitz.com/edit/vitejs-vite-q3yh8t?file=src%2Fmain.tsx

Steps to reproduce

  1. Remove the package-lock.json
  2. npm install && npm run dev

System Info

❯ npx envinfo --system --npmPackages '{vite,@vitejs/*}' --binaries --browsers
Need to install the following packages:
[email protected]
 

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-react: ^4.3.4 => 4.3.4 
    vite: ^6.0.1 => 6.0.1

Used Package Manager

npm

Logs

No response

Validations

@hi-ogawa
Copy link
Collaborator

react({ jsxRuntime: 'classic' }) is needed for React 16 https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md#jsxruntime
Then you need to manually have import React from "react" for jsx files https://stackblitz.com/edit/vitejs-vite-n8d2mc?file=tsconfig.app.json. You can use compilerOptions.jsx: "react" to ensure typescript help catching missing React.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants