Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected identifier but found "import" #53991

Closed
JurgenThijs opened this issue Dec 20, 2024 · 6 comments
Closed

Expected identifier but found "import" #53991

JurgenThijs opened this issue Dec 20, 2024 · 6 comments

Comments

@JurgenThijs
Copy link

JurgenThijs commented Dec 20, 2024

Laravel Version

11.36.1

PHP Version

8.3.14

Database Driver & Version

No response

Description

When creating a new project and running the npm run build or npm run dev, I get the following error

npm run build  ✔  at 11:20:23 

build
vite build

✘ [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 /Users/jurgen/code/project/vite.config.js
error during build:
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 (/Users/jurgen/code/project/node_modules/esbuild/lib/main.js:1476:15)
at /Users/jurgen/code/project/node_modules/esbuild/lib/main.js:945:25
at runOnEndCallbacks (/Users/jurgen/code/project/node_modules/esbuild/lib/main.js:1316:45)
at buildResponseToResult (/Users/jurgen/code/project/node_modules/esbuild/lib/main.js:943:7)
at /Users/jurgen/code/project/node_modules/esbuild/lib/main.js:970:16
at responseCallbacks. (/Users/jurgen/code/project/node_modules/esbuild/lib/main.js:622:9)
at handleIncomingPacket (/Users/jurgen/code/project/node_modules/esbuild/lib/main.js:677:12)
at Socket.readFromStdout (/Users/jurgen/code/project/node_modules/esbuild/lib/main.js:600:7)
at Socket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:561:12)

Steps To Reproduce

laravel new project
cd project
npm install && npm run build

Tested it out on macOS and Windows with Laravel Herd

Node version: 22.11.0
Npm version: 10.9.0

@morpheus7CS
Copy link
Contributor

Can confirm this, I'm getting the same issue.

From what I have gathered so far, Vite v6 which has some breaking changes regarding ESM modules.

@JurgenThijs
Copy link
Author

JurgenThijs commented Dec 20, 2024

Indeed.

Doing a search on vitejs i found this issue as well.
There it is linked to an issue from esbuild

I then tried updating the vite version in package.json from "^6.0" to "^5.0".
Did an npm updated and was able to do npm run dev

@patak-dev
Copy link

you can update to vite@6.0.5, we've pinned esbuild to 0.24.0 until the regression is fixed upstream

@timacdonald
Copy link
Member

This was a temporary upstream issue, as @patak-dev mentioned, that has been addressed in both Vite and esbuild.

Update your dependencies and you should be good to go.

@timacdonald
Copy link
Member

p.s., thanks for the fix, @patak-dev ❤️

@JurgenThijs
Copy link
Author

Indeed, Updating vite to 6.0.5 does the trick :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants