iftekhs's avatar
Level 13

Vite react dosent show import errors.

Hi, I'm using vite react and I created the react app using npm create vite@latest and when I create a .jsx file and use a component inside of it but I forgot to import that component It dosent show me error in the code that I forgot to import it but If I use .js file it shows me the error. I'm not sure if it has anything to do with typescript because If i dont import it and hover over the component it shows type any. How can I fix this issue to get errors for imports in .jsx file?

0 likes
1 reply
LaryAI's avatar
Level 58

This issue is caused by the fact that Vite does not perform type checking by default for .jsx files. To enable type checking for .jsx files, you can add the following configuration to your vite.config.js file:

// vite.config.js
export default {
  plugins: [
    {
      name: 'typescript',
      // enable type checking for .jsx files
      // you can also add other file extensions here
      // such as .tsx, .ts, etc.
      enableJsx: true,
    },
  ],
};

This will enable type checking for .jsx files and you should now see import errors when you forget to import a component.

Please or to participate in this conversation.