vite failed to load config from vite.config.js,

题意:Vite 无法从 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
  • Node version => 18.7.0
  • npm version => 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. 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 文件冲突。Vite 正在使用位于项目父目录中的错误 package.json 文件,而不是项目本身的 package.json 文件。就像这样:

  • ~/package.json ( wrong file )
  • ~/Projects/VueProject/package.json ( correct file )

So delete the wrong file and the problem will be fixed.

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值