-
Hello, I'm trying to use create a react project that use both javascript and typescript. I got the following error:
Here's a minimum reproduction: https://github.com/vutpov/test-vite-ts-js-react |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I am not familiar to React, but I edit the example in Vite document to use js and ts together, and it worked. Refer to stackblitz |
Beta Was this translation helpful? Give feedback.
-
In your repo: // vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
}); // src/Counter.jsx
import { useState } from 'react'
import viteLogo from '/vite.svg'
import reactLogo from './assets/react.svg'
function Counter() {
// ...
} // src/App.tsx
import "./App.css";
- import Counter from "./Counter.js";
+ import Counter from "./Counter.jsx";
// ... Will fix it. |
Beta Was this translation helpful? Give feedback.
-
By default, |
Beta Was this translation helpful? Give feedback.
By default,
esbuild
is applied tots
,jsx
andtsx
files, You don't need to specify loaders foresbuild
.