vue3.0+vite+ts项目搭建(报错处理)

转载自: https://www.cnblogs.com/ToBeBest/p/15597961.html

报错一

 

warning package.json: No license field
$ vue-tsc --noEmit && vite build

 

 

 

 解决方案,添加这两行,只添加一个是没有用的

 

 报错二

node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1193:6 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.

 

 

 把tsconfig.json中的isolatedModules设置为false

 

报错三

yarn dev 不报错,build就报错

$ vue-tsc --noEmit && vite build
src/pages/home.vue:9:8 - error TS2339: Property 'appContext' does not exist on type 'ComponentInternalInstance | null'.

src/utils/request.ts:7:16 - error TS7016: Could not find a declaration file for module 'qs'

 

 

 解决方式将package.json中的build部分改掉

 

 改成这个样子就不再报错也可以正常打包了

 报错四

打包报错

 

这个是打包配置文件写错了,改成这样就好了

 报错五

 

打包的时候出现以下报错:

warnings when minifying css:
> <stdin>:9:1: warning: "@charset" must be the first rule in the file
9 │ }@charset "UTF-8";

 

 解决方案:修改vite.config.ts文件配置

css部分加上charset: false

完整代码如图

 报错六

 

vant采用cdn引入的方式报错

Uncaught (in promise) TypeError: Cannot read property 'proxy' of null
at Xe (vant.min.js:1)

 解决方案,换用从vite.config.ts中引入CDN

上面这种报错是在从index.html引入CDN的情况下报错的

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章