Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors while starting vite + react [closed]

Tags:

reactjs

vite

I am making a fullstack project, I have a parent folder in which I have frontend and backend folder. Frontend folder is my Vite project but when I do npm run dev it just shows errors:

> [email protected] dev
> vite

✘ [ERROR] Expected identifier but found "import"

    (define name):1:0:
      1 │ import.meta.dirname
        ╵ ~~~~~~

✘ [ERROR] Expected identifier but found "import"

    (define name):1:0:
      1 │ import.meta.filename
        ╵ ~~~~~~

✘ [ERROR] Expected identifier but found "import"

    (define name):1:0:
      1 │ import.meta.url
        ╵ ~~~~~~

failed to load config from /home/pankaj/study/sneaker-project/frontend/vite.config.js
error when starting dev server:
Error: Build failed with 3 errors:
(define name):1:0: ERROR: Expected identifier but found "import"
(define name):1:0: ERROR: Expected identifier but found "import"
(define name):1:0: ERROR: Expected identifier but found "import"
    at failureErrorWithLog (/home/pankaj/study/sneaker-project/frontend/node_modules/esbuild/lib/main.js:1476:15)
    at /home/pankaj/study/sneaker-project/frontend/node_modules/esbuild/lib/main.js:945:25
    at runOnEndCallbacks (/home/pankaj/study/sneaker-project/frontend/node_modules/esbuild/lib/main.js:1316:45)
    at buildResponseToResult (/home/pankaj/study/sneaker-project/frontend/node_modules/esbuild/lib/main.js:943:7)
    at /home/pankaj/study/sneaker-project/frontend/node_modules/esbuild/lib/main.js:970:16
    at responseCallbacks.<computed> (/home/pankaj/study/sneaker-project/frontend/node_modules/esbuild/lib/main.js:622:9)
    at handleIncomingPacket (/home/pankaj/study/sneaker-project/frontend/node_modules/esbuild/lib/main.js:677:12)
    at Socket.readFromStdout (/home/pankaj/study/sneaker-project/frontend/node_modules/esbuild/lib/main.js:600:7)
    at Socket.emit (node:events:524:28)
    at addChunk (node:internal/streams/readable:561:12)
like image 206
PanKaJxD Avatar asked Sep 13 '25 00:09

PanKaJxD


2 Answers

Step 1: npm i -D [email protected]

Step 2: npm i

Step 3: npm run dev

like image 56
Codex Solutions Avatar answered Sep 14 '25 12:09

Codex Solutions


I am having the same error with laravel project. Looks like "vite": "^6.0.4" is causing the issue. Downgrading works at this moment

npm uninstall vite

npm install vite@^5
like image 38
Onur Karagül Avatar answered Sep 14 '25 13:09

Onur Karagül