改bug日常:解决Vite+Vue3项目中ts(2792)错误

764 阅读1分钟

vite+vue3项目,安装vite后

1.main.ts文件报错

 import { createApp } from 'vue'
 import App from './App.vue'

英文错误信息:“Cannot find module ‘vue’. Did you mean to set the ‘moduleResolution’ option to ‘node’, or to add aliases to the ‘paths’ option?ts(2792)”,

image-20230907083327898

2.tsconfig.config.json文件报错

 {
   "extends": "@vue/tsconfig/tsconfig.dom.json",
   "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
   "exclude": ["src/**/__tests__/*"],
   "compilerOptions": {
     "composite": true,
     "baseUrl": ".",
     "paths": {
       "@/*": ["./src/*"]
     }
   }
 }

英文错误信息: “JSON schema for the TypeScript compiler’s configuration file Option ‘–resolveJsonModule’ cannot be specified without ‘node’ module resolution strategy.ts”

image-20230907084607957

解决方法

在tsconfig.config.json文件添加:

 "moduleResolution": "node"

image-20230907085214053