vue3-vite安装后main.ts文件和tsconfig.app.json文件报错解决办法

 更新时间:2023年12月19日 09:27:22   作者:零OO  
Vue.js是一个流行的JavaScript框架,它可以帮助开发者构建交互式Web应用程序,这篇文章主要给大家介绍了关于vue3-vite安装后main.ts文件和tsconfig.app.json文件报错解决办法,需要的朋友可以参考下

报错现象:

安装vite后“main.ts” 和 “tsconfig.app.json” 文件报错

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import router from './router'

安装vite后,“main.ts” 文件中这几行出现了报错,如图所示:

鼠标移动到报错位置,显示提示:
“Cannot find module ‘vue’. Did you mean to set the ‘moduleResolution’ option to ‘node’, or to add aliases to the ‘paths’ option?ts(2792)”,
如图所示:

“tsconfig.app.json” 文件也会报错,如图:

鼠标移动到报错的红色下划线位置,出现错误提示 “JSON schema for the TypeScript compiler’s configuration file
Option ‘–resolveJsonModule’ cannot be specified without ‘node’ module resolution strategy.ts”,如图:

解决方法

根据报错提示:“Cannot find module ‘vue’. Did you mean to set the ‘moduleResolution’ option to ‘node’, or to add aliases to the ‘paths’ option?ts(2792)”,

在 “tsconfig.app.json” 文件 的"compilerOptions" 选项中添加配置- - -“moduleResolution”: “node”,添加后保存文件,“main.ts” 和 “tsconfig.app.json” 文件中的报错就消失了。

总结 

到此这篇关于vue3-vite安装后main.ts文件和tsconfig.app.json文件报错解决办法的文章就介绍到这了,更多相关vue3-vite安装后文件报错内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

最新评论