While developing a Vue.js 3.0 project using the vite tool, a configuration issue caused the project to run with the following error message:
16:17:27 [vite] page reload main.js
Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.
16:17:28 [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.
Plugin: vite:import-analysis
File: /home/projects/vitejs-vite-der4uu/App.vue
We need to install the plug-in @@vitejs/plugin-vue that uses error prompts.
The solution steps are as follows:
1. Install dependent plug-ins first
npm install @vitejs/plugin-vue -D
2. Then configure the vite project configuration file: 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()],
});
In this way, we have configured the vite project to recognize the ability to parse single-file components with a .vue suffix.
3. Rerun
npm run dev
This is the problem. It is solved perfectly.
Read More:
- [Solved] devTools failed to load sourcemap: Could not parse content for map
- [Solved] Nuxt Import qrcodejs2.js / QRCode.js Error: document is not defined
- About JS error uncaught syntax error: invalid shorthand property initializer
- js: SyntaxError: Cannot use import statement outside a module
- Vue JS import font.css error [How to Solve]
- ArcGIS API for JavaScript version 4. X updated and the project startup error: Module parse failed: Unexpected token(… …
- [Solved] echarts Draw Errror: echarts-d9fd185e.js:31447 Uncaught (in promise) Error: Initialize failed: invalid dom.
- Vue Import three.JS error: Unexpected token [How to Solve]
- [Chrome]: DevTools failed to load source map… (How to Solve)
- Solution to some map files in JS folder after Vue packaging (remove the map. JS file)
- Vue Import element-plus Error: Failed to resolve import “element-pluslibtheme-chalkindex.css“ from “src
- error in ./node_modules/@lit/reactive-element/decorators/state.jsModule parse failed: Unexpected
- [Solved] vue3vite Error: Failed to resolve import “@vue/server-renderer from “src\App.vue“. Does the file exist
- [Solved] Error: Transform failed with 1 error: error: Invalid option in transform() call: “jsx“
- [Solved] Turf.js error: uncaught (in promise) error: the solution of invalid unit
- [Solved] Failed to load plugin ‘vue‘ declared in ‘.eslintrc.js‘: createRequire is not a function
- Solution to build error in Vue project (error in static/JS)/vendor.xxxxx.js from UglifyJs)
- [Solved] Failed to compile with 1 error. Syntax Error: Error: Loading PostCSS Plugin failed: Cannot find modul
- [Solved] Vue Use gzip Package Error: Rule can only have one resource source
- [Solved] Uncaught (in promise) DOMException: Failed to load because no supported source was found.