[plugin:vite:import-analysis] Failed to resolve import “@/views/Login.vue“ from “src\router\index.ts

报错截图

[plugin:vite:import-analysis] Failed to resolve import “@/views/Login.vue“ from “src\router\index.ts_第1张图片

报错原因是没有引入@相关的配置

先安装path模块

npm install --save-dev @types/node

修改 vite.config.js 文件


import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  }
})

在重新启动项目就可以了

你可能感兴趣的:(vue.js,javascript,前端)