简体   繁体   English

无法从 \Project\vuejs-frontend\vite.config.js 加载配置:VueJS

[英]Failed to load config from \Project\vuejs-frontend\vite.config.js: VueJS

My Project was running fine yesterday but after revisiting project today I came across this error when trying to run the project.我的项目昨天运行良好,但今天重新访问项目后,我在尝试运行项目时遇到了这个错误。

Here is my vite.config.js file:这是我的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)),
    },
  },
});

Here is the error I'm getting:这是我得到的错误:

failed to load config from C:\Users\Desktop\Learn\Project\vuejs-frontend\vite.config.js
error when starting dev server:
Error: The service was stopped
    at C:\Users\Desktop\Learn\Project\vuejs-frontend\node_modules\esbuild\lib\main.js:1337:25
    at C:\Users\Desktop\Learn\Project\vuejs-frontend\node_modules\esbuild\lib\main.js:666:9
    at Socket.afterClose (C:\Users\Desktop\Learn\Project\vuejs-frontend\node_modules\esbuild\lib\main.js:644:7)
    at Socket.emit (node:events:539:35)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Please share with me any helpful tips you know.请与我分享您知道的任何有用的提示。 Thank you谢谢

Please check your node version, in my case i update my node version {node: 'v14.17.6'} as showed bellow, and everything goes well.请检查您的节点版本,在我的情况下,我更新了我的节点版本 {node: 'v14.17.6'},如下所示,一切顺利。

--- Log --- package: 'vite@3.0.2', required: { node: '^14.18.0 || ---日志---包:'vite@3.0.2',必需:{节点:'^14.18.0 || >=16.0.0' }, current: { node: 'v14.17.6', npm: '8.15.0' } >=16.0.0'},当前:{节点:'v14.17.6',npm:'8.15.0'}

Hope it help希望有帮助

Pls download the latest version of node js https://nodejs.org/en/download/请下载最新版本的node js https://nodejs.org/en/download/

The error seems to stem from fact that laravel uses vite 2 while current vite is 3 and yet seems jetstream just installs latest dependencies without considering such.该错误似乎源于以下事实:laravel 使用 vite 2 而当前 vite 是 3,但似乎 jetstream 只是安装了最新的依赖项而没有考虑到这一点。 Hence you have to manually try out versions that play well with each other.因此,您必须手动尝试相互配合良好的版本。 Currently what worked for me is:目前对我有用的是:

    "@vitejs/plugin-vue": "^2.3.3",
    "laravel-vite-plugin": "^0.2.1",
    "vite": "^2.9.11",
    "vue": "^3.2.31"
    "tailwindcss": "^3.1.0",

it seems the laravel-vite-plugin are laravel-vite-plugin dependencies are the most conflicting.似乎laravel-vite-pluginlaravel-vite-plugin依赖项是最冲突的。

To make the changes you can edit the package.json and run npm install or npm install the specific packages specifying the version get installation the link from npm for correct format.要进行更改,您可以编辑 package.json 并运行 npm 安装或 npm 安装指定版本的特定包从 npm 获取正确格式的安装链接。

This held me down for quite some hours.这让我沮丧了好几个小时。 Thing is not even about node as above answer as myself was on 16.17, though check on that too, upgrading node ended up in up in more problems about openssl because i had postgres installed too which adds the config in path.事情甚至与我在 16.17 上的上述答案无关,尽管也检查了这一点,升级节点最终导致了更多关于 openssl 的问题,因为我也安装了 postgres,它在路径中添加了配置。 I did not want to touch that.我不想碰那个。 After fidgeting around creating separate project and installing breeze separately i caught the error.在烦躁地创建单独的项目并单独安装 breeze 之后,我发现了错误。

I got a hint of whats going on from this tweet from Povilas of Laravel daily after hours of scouring the inte.net.在搜索 inte.net 数小时后,我每天从 Povilas Laravel 的这条推文中了解到发生了什么事。

Question is similar to mine if am not wrong:如果我没有错的话,问题与我的相似:

check it out 看看这个

If you are running a newer verison of node.js, I am running 18.x and still want to use Vite, then adapt your code a little bit.如果你运行的是 node.js 的较新版本,我运行的是 18.x 并且仍然想使用 Vite,那么请稍微调整一下你的代码。

change the code that sets the export default更改设置导出默认值的代码

// vite.config.js
export default defineConfig({
  build: {
    rollupOptions: {
      // https://rollupjs.org/guide/en/#big-list-of-options
    }
  }
})

to be成为

  const defineConfig = ({
  build: {
    rollupOptions: {
      // https://rollupjs.org/guide/en/#big-list-of-options
    }
  }
});
export default defineConfig;

basically you are setting defineConfig to be a constant and then exporting that.基本上,您将 defineConfig 设置为常量,然后将其导出。 It works fine on any version of node.js它适用于任何版本的 node.js

I´m having the same problem but haven´t been able to solve the problem, I thought the problem may have been mine node version but I have 16.17.0.我遇到了同样的问题,但一直无法解决问题,我认为问题可能出在我的节点版本上,但我有 16.17.0。

this is how my vite.config.js file looks:这是我的 vite.config.js 文件的样子:

     import { defineConfig } from "vite";
     import react from "@vitejs/plugin-react";

        export default defineConfig({
           plugins: [react()],
      });

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

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