【报错】Failed to resolve import “@/..“ from “src/...“ @找不到路径

安装path

npm install --save-dev @types/node

配置

// vite.config.ts 
import {
    
     defineConfig } from "vite"
import react from "@vitejs/plugin-react"

import path from "path" // 需安装此模块

// https://vitejs.dev/config/
export default defineConfig({
    
    
  plugins: [react()],
  resolve: {
    
    
    alias: {
    
    
      // 这里就是需要配置resolve里的别名
      "@": path.join(__dirname, "./src") // path记得引入
    }
  }
})

// tsconfig.json
"compilerOptions": {
    
    
  "baseUrl": ".",
  "paths": {
    
    
    "@/*":["./src/*"]
  }
}