DEV Community

SeongKuk Han
SeongKuk Han

Posted on

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

A problem while migrating from CRA to Vite


Error Message:

[plugin:vite:import-analysis] Failed to resolve import "react/jsx-dev-runtime" from "src/index.tsx". Does the file exist?
Enter fullscreen mode Exit fullscreen mode

Solution: Add an option classic to jsxRuntime of the plugin react in the vite config file.

[vite.config.ts]

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsconfigPaths from 'vite-tsconfig-paths';
import svgrPlugin from 'vite-plugin-svgr';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react({
    jsxRuntime: 'classic' // Add this line
  }), viteTsconfigPaths(), svgrPlugin()],
});
Enter fullscreen mode Exit fullscreen mode

@vitejs/plugin-react : By default, the plugin uses the automatic JSX runtime. However, if you encounter any issues, you may opt out using the jsxRuntime option.

Top comments (7)

Collapse
 
bhatvikrant profile image
Vikrant Bhat

This removed that error but now I'm getting the react import not found error

Collapse
 
lico profile image
SeongKuk Han

If you can share the code or how to reproduce, I will look into that.

Collapse
 
ch264 profile image
Christina Hastenrath

Thank you, this saved me

Collapse
 
lico profile image
SeongKuk Han

Glad to hear that 👍

Collapse
 
fuvavi profile image
Fuvavi

Thanks so much. It's work very well.

Collapse
 
lico profile image
SeongKuk Han

glad it worked for you :)

Collapse
 
doankimhuyit profile image
Doan Kim Huy

Thank you so much!!!