skip to Main Content

I’m working on a React and TypeScript project using Vite for bundling. The issue arises during the build process. I’ve installed all dependencies correctly, and the dev server runs fine, but the build fails with errors related to import.meta.

Error:
Here’s the error message I’m getting:

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
      ╵ ~~~~~~

failed to load config from path/to/vite.config.ts
error during build:
Error: Build failed with 3 errors:
...


2

Answers


  1. To resolve this issue, try downgrading esbuild to version 0.24.0 by running the following command:

    npm install -D [email protected]
    

    This should fix the build errors related to import.meta.

    Login or Signup to reply.
  2. Thanks Kshtiz Ji for the answer and Arun for the Question. You saved my whole week. I have been trying this to fix.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search