Skip to content

ERROR: Expected identifier but found "import" #4010

@ti777777

Description

@ti777777

Describe what esbuild is doing incorrectly and what it should be doing instead.

When using Vite to create a new project, it fails to start properly. Downgrading esbuild to version 0.24.0 resolves the issue.

OS: Windows 10
Node.js Version: v22.12.0

PS C:\react-app> npm run dev

react-app@0.0.0 dev
vite

X [ERROR] Expected identifier but found "import"

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

X [ERROR] Expected identifier but found "import"

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

X [ERROR] Expected identifier but found "import"

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

failed to load config from C:\react-app\vite.config.ts
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 (C:\react-app\node_modules\esbuild\lib\main.js:1476:15)
at C:\react-app\node_modules\esbuild\lib\main.js:945:25
at runOnEndCallbacks (C:\react-app\node_modules\esbuild\lib\main.js:1316:45)
at buildResponseToResult (C:\react-app\node_modules\esbuild\lib\main.js:943:7)
at C:\react-app\node_modules\esbuild\lib\main.js:970:16
at responseCallbacks. (C:\react-app\node_modules\esbuild\lib\main.js:622:9)
at handleIncomingPacket (C:\react-app\node_modules\esbuild\lib\main.js:677:12)
at Socket.readFromStdout (C:\react-app\node_modules\esbuild\lib\main.js:600:7)
at Socket.emit (node:events:524:28)
at addChunk (node:internal/streams/readable:561:12)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions