Vite使用報錯解決方法合集
1.npm install 報錯
解決方法:運行下列命令即可
npm audit fix --force
2.vite創(chuàng)建vue3項目報錯
報錯:Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.
解決方法:
1)安裝 @vitejs/plugin-vue
npm i @vitejs/plugin-vue
2)重新 npm install
npm install
3)添加配置文件vite.config.js
// vite.config.js import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()] })
4)重新運行即可
npm run dev
3.improt引入文件報錯
報錯:無法找到模塊“../views/HomeView.vue”的聲明文件。“/Users/lianwei/Desktop/old/PersonalProject/vite-demo2/src/views/HomeView.vue.js”隱式擁有 "any" 類型。
解決方法:找到src/vite-env.d.ts 添加以下代碼
// 在文件中加上 declare module '*.vue' { import type { DefineComponent } from 'vue' const component: DefineComponent<{}, {}, any> export default component } // 或者 declare module '*.vue' { import type { DefineComponent } from 'vue' const component: ComponentOptions | ComponentOptions['setup'] export default component }
總結(jié)
到此這篇關(guān)于Vite使用報錯解決方法的文章就介紹到這了,更多相關(guān)Vite使用報錯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue3+vite項目中按需引入vant報錯:Failed?to?resolve?import的解決方案
- vite配置別名并處理報錯:找不到模塊“xxx”或其相應(yīng)的類型聲明方法詳解
- 解決vue?vite啟動項目報錯ERROR:?Unexpected?“\x88“?in?JSON?的問題
- vue3+vite中報錯信息處理方法Error: Module “path“ has been externalized for browser compatibility...
- vue3+vite:src使用require動態(tài)導(dǎo)入圖片報錯的最新解決方法
- Vue3之Vite中由element?ui更新導(dǎo)致的啟動報錯解決
- Vite3 Svelte3構(gòu)建Web應(yīng)用報錯process is not defined
相關(guān)文章
vue中報錯Duplicate?keys?detected:'1'.?This?may?c
我們在vue開發(fā)過程中常會遇到一些錯誤,這篇文章主要給大家介紹了關(guān)于vue中報錯Duplicate?keys?detected:‘1‘.?This?may?cause?an?update?error的解決方法,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2023-03-03vue3項目導(dǎo)入異常Error:@vitejs/PLUGIN-vue?requires?vue?(>=3.2.13
這篇文章主要給大家介紹了關(guān)于vue3項目導(dǎo)入異常Error:@vitejs/PLUGIN-vue?requires?vue?(>=3.2.13)的解決辦法,文中將解決辦法介紹的非常詳細,需要的朋友可以參考下2024-01-01