vue3報(bào)錯(cuò)提示 找不到模塊“/App.vue”或其相應(yīng)的類型聲明
場(chǎng)景復(fù)現(xiàn)
在使用 vue3?vite?ts
或者 js
搭建前端框架時(shí),在main.ts
或者main.js
中引入/App.vue
報(bào)錯(cuò)。報(bào)錯(cuò)內(nèi)容為 /App.vue不是模塊。下面我們分vue3+js和vue3+ts兩種情況討論,給出相應(yīng)的解決方案。
情況一、vue3.0+js
報(bào)錯(cuò)顯示:
報(bào)錯(cuò)原因:javascript只能理解.js
文件,無(wú)法理解.vue
文件。
解決方案:根目錄新建jsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*":[
"src/*"
]
}
},
"exclude": [
"node_modeules",
"dist"
]
}
此時(shí)問題已經(jīng)解決:??????
情況二、vue3.0+ts
報(bào)錯(cuò)顯示:
報(bào)錯(cuò)原因:typescript只能理解.ts
文件,無(wú)法理解.vue
文件。
方案一:根目錄新建env.d.ts
在根目錄新建env.d.ts文件,寫入以下內(nèi)容:
declare module '*.vue' {
import type { DefineComponent } from 'vue'
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any>
export default component
}
也可以解決問題,缺點(diǎn)是需要一直打開
方案二:根目錄新建tsconfig.json
在根目錄新建tsconfig.json
文件,寫入以下內(nèi)容:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-824883.html
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": false,
"jsx": "preserve",
"moduleResolution": "node"
}
}
此時(shí)報(bào)錯(cuò)已解決 ??????文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-824883.html
到了這里,關(guān)于vue3+vite在main.ts或者main.js文件中引入/App.vue報(bào)錯(cuò)(/App.vue不是模塊)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!