25

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:

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

1
  • I saw and used some projects that import fileURLToPath and URL but from url, not node:url. Otherwise looks fine to me Commented Jul 18, 2022 at 14:23

11 Answers 11

14

Please check your node version, in my case i update my node version {node: 'v14.17.6'} as showed bellow, and everything goes well.

--- Log --- package: '[email protected]', required: { node: '^14.18.0 || >=16.0.0' }, current: { node: 'v14.17.6', npm: '8.15.0' }

Hope it help

Sign up to request clarification or add additional context in comments.

Comments

10

I solved that by:

  1. deleting node_modules/ and package-lock.json.
  2. reinstalling packages with npm install.

npm run dev should work properly now.

2 Comments

What does your answer add to existing 11 answers? Including ones which say to delete node_modules?
deleting only node_modules didn't work for me until I deleted package-lock.json too. No other answer says that.
9

I have take a similar error prompt but I am work with react, I just solved this typing the command:

npm update

Comments

4

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.

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. It works fine on any version of node js

Comments

3

I had the same problem and my fix was to remove node_modules folder and then re-run npm install

Comments

1

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. 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.

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.

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. I did not want to touch that. After fidgeting around creating separate project and installing breeze separately i caught the error.

I got a hint of whats going on from this tweet from Povilas of Laravel daily after hours of scouring the internet.

Question is similar to mine if am not wrong:

check it out

Comments

0

I also got the same problem, and it's because your Vite version doesn't match node version.

you need to update your node to the latest, it's very easy.

just download the latest version of node at https://nodejs.org/en/ and your problem will be solved.

Comments

0

I just had the same error while setting up and working with vite, i solved it by importing import { resolve } from 'path' in the my vite.config.js file as seen in the doc here https://vitejs.dev/guide/build.html#library-mode

Hope that helps!

Comments

0

Installing the latest node version form Node.js solved the issue for me. Check your version using command -

node -v

My old version was - v14.15.1

New version is - v18.17.1

Comments

0

I just did rm -rf node_modules and then npm install but the npm install was still displaying esolve error and then i went to win + R and and input cmd and i added this line of command del /f /q

C:\Users\shenc\Documents\tests\node_modules\esbuild-windows-64\esbuild.exe

then i went back to my terminal and did npm install force and boom when i run the npm run dev again it worked without stress.

1 Comment

Please format your code-snippets to make it more readable.
-1

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.

this is how my vite.config.js file looks:

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

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

1 Comment

This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.