简体   繁体   English

vite 无法从 vite.config.js 加载配置,

[英]vite failed to load config from vite.config.js,

I created a new vue app by doing these ( according to vue docs )我通过这样做创建了一个新的 vue 应用程序(根据 vue 文档

  1. npm init vue@latest
  2. npm install

Then I try to run npm run dev .Then this happened.然后我尝试运行npm run dev 。然后发生了这种情况。

在此处输入图像描述

My environments are these我的环境是这些

  • OS => Ubuntu操作系统 => Ubuntu
  • Node version => 18.7.0节点版本 => 18.7.0
  • npm version => 8.15.0 npm 版本 => 8.15.0

My package.json我的 package.json

{
  "name": "vue-project",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview --port 4173"
  },
  "dependencies": {
    "vue": "^3.2.37"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^3.0.1",
    "vite": "^3.0.4"
  }
}

My vite.config.js我的 vite.config.js

import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

I have been searching for a while now but no avail.Thanks in advance.我一直在寻找一段时间,但无济于事。在此先感谢。

Finally I found the solution.最后我找到了解决方案。 The problem was because of the package.json file conflict.问题是因为package.json文件冲突。 Vite is using the wrong package.json file located in the Project's parent directory instead of project's own package.json file.Like this - Vite is using the wrong package.json file located in the Project's parent directory instead of project's own package.json file.Like this -

  • ~/package.json ( wrong file ) ~/package.json (错误文件)
  • ~/Projects/VueProject/package.json ( correct file ) ~/Projects/VueProject/package.json (正确的文件)

So delete the wrong file and the problem will be fixed.所以删除错误的文件,问题就会得到解决。

Thanks to this github issue answer package.json:1:0: error: Unexpected end of file感谢这个 github 问题答案package.json:1:0: error: Unexpected end of file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM