繁体   English   中英

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

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

我通过这样做创建了一个新的 vue 应用程序(根据 vue 文档

  1. npm init vue@latest
  2. npm install

然后我尝试运行npm run dev 。然后发生了这种情况。

在此处输入图像描述

我的环境是这些

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

我的 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"
  }
}

我的 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))
    }
  }
})

我一直在寻找一段时间,但无济于事。在此先感谢。

最后我找到了解决方案。 问题是因为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 -

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

所以删除错误的文件,问题就会得到解决。

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

暂无
暂无

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

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