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

Fails to load config with Excepted identifier but found "import" error #19018

Open
7 tasks done
zhangtao25 opened this issue Dec 20, 2024 · 47 comments
Open
7 tasks done
Labels
bug: upstream Bug in a dependency of Vite p5-urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority)

Comments

@zhangtao25
Copy link

zhangtao25 commented Dec 20, 2024

Note: vite@6.0.5 is out pinning to esbuild 0.24.0 until @sapphi-red's PR to esbuild is merged and released, you can update to latest vite to fix this issue. Leaving this issue open as we'll revert the temporary fix soon.

Workaround and the cause

It seems a change in esbuild 0.24.1 is affecting Vite's config loader: evanw/esbuild#4010

The current workaround is to set overrides in package managers:

Edited by @sapphi-red


Describe the bug

Screenshot 0006-12-20 at 14 20 15

Reproduction

pnpm create vite@latest; babel-react

Steps to reproduce

No response

System Info

System:
    OS: macOS 15.0
    CPU: (8) arm64 Apple M1 Pro
    Memory: 144.56 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.3.0 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.9.0 - /usr/local/bin/npm
    pnpm: 9.15.0 - /usr/local/bin/pnpm
    bun: 1.1.28 - ~/.bun/bin/bun
  Browsers:
    Chrome: 131.0.6778.205
    Safari: 18.0
  npmPackages:
    @vitejs/plugin-react: ^4.3.4 => 4.3.4
    vite: ^6.0.3 => 6.0.4

Used Package Manager

pnpm

Logs

No response

Validations

@ocavue
Copy link
Contributor

ocavue commented Dec 20, 2024

This error can be reproduced by using pnpm create vite with the react template, shown below:


$ pnpm create vite
.../Library/pnpm/store/v3/tmp/dlx-81687  |   +1 +
.../Library/pnpm/store/v3/tmp/dlx-81687  | Progress: resolved 1, reused 1, downloaded 0, added 1, done
✔ Project name: … vite-project
✔ Select a framework: › React
✔ Select a variant: › TypeScript

Scaffolding project in /private/tmp/testvite3/vite-project...

Done. Now run:

  cd vite-project
  pnpm install
  pnpm run dev


$ cd vite-project

$ pnpm install
Packages: +182
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 224, reused 180, downloaded 2, added 182, done

dependencies:
+ react 18.3.1 (19.0.0 is available)
+ react-dom 18.3.1 (19.0.0 is available)

devDependencies:
+ @eslint/js 9.17.0
+ @types/react 18.3.18 (19.0.2 is available)
+ @types/react-dom 18.3.5 (19.0.2 is available)
+ @vitejs/plugin-react 4.3.4
+ eslint 9.17.0
+ eslint-plugin-react-hooks 5.1.0
+ eslint-plugin-react-refresh 0.4.16
+ globals 15.14.0
+ typescript 5.6.3 (5.7.2 is available)
+ typescript-eslint 8.18.1
+ vite 6.0.4

Done in 3.5s

$ pnpm run build

> vite-project@0.0.0 build /private/tmp/testvite3/vite-project
> tsc -b && 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 /private/tmp/testvite3/vite-project/vite.config.ts
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 (/private/tmp/testvite3/vite-project/node_modules/.pnpm/esbuild@0.24.1/node_modules/esbuild/lib/main.js:1476:15)
    at /private/tmp/testvite3/vite-project/node_modules/.pnpm/esbuild@0.24.1/node_modules/esbuild/lib/main.js:945:25
    at runOnEndCallbacks (/private/tmp/testvite3/vite-project/node_modules/.pnpm/esbuild@0.24.1/node_modules/esbuild/lib/main.js:1316:45)
    at buildResponseToResult (/private/tmp/testvite3/vite-project/node_modules/.pnpm/esbuild@0.24.1/node_modules/esbuild/lib/main.js:943:7)
    at /private/tmp/testvite3/vite-project/node_modules/.pnpm/esbuild@0.24.1/node_modules/esbuild/lib/main.js:970:16
    at responseCallbacks.<computed> (/private/tmp/testvite3/vite-project/node_modules/.pnpm/esbuild@0.24.1/node_modules/esbuild/lib/main.js:622:9)
    at handleIncomingPacket (/private/tmp/testvite3/vite-project/node_modules/.pnpm/esbuild@0.24.1/node_modules/esbuild/lib/main.js:677:12)
    at Socket.readFromStdout (/private/tmp/testvite3/vite-project/node_modules/.pnpm/esbuild@0.24.1/node_modules/esbuild/lib/main.js:600:7)
    at Socket.emit (node:events:518:28)
    at addChunk (node:internal/streams/readable:561:12)
 ELIFECYCLE  Command failed with exit code 1.

@nsnail

This comment was marked as duplicate.

@MissGwen

This comment was marked as duplicate.

@sweetyguazi

This comment was marked as duplicate.

@eqs

This comment was marked as duplicate.

@kurone-kito
Copy link

I found the same problem in my environment, but the following command temporarily solved it.
I hope it works in your environment as well.

pnpm add -D esbuild@=0.24.0
pnpm dedupe

@pga5e
Copy link

pga5e commented Dec 20, 2024

+1 ran a totally new completely clean build in new pc and got this same error

@0x2E
Copy link

0x2E commented Dec 20, 2024

evanw/esbuild#4010

@shiqi0319

This comment was marked as spam.

@suhailkc
Copy link

npm i -D esbuild@0.24.0

@Divyanshu1020

This comment was marked as spam.

@lingrottin
Copy link

+1 but downgrading esbuild solves that 😸

@sai-oduri
Copy link

downgrade vite version working for now.
run this in your project directory
npm uninstall vite
npm i -D vite@5
or simply
npm i -D vite@5

@thomaskang08

This comment was marked as duplicate.

@CHMOSE023
Copy link

npm view create-vite versions --json

npm create vite@5.5.5

5.5.5 这个版本可用

@Mxtzz

This comment was marked as spam.

@Mxtzz
Copy link

Mxtzz commented Dec 20, 2024

删除lock文件,删除node_modules,再pnpm install就会复现。

临时修复 pnpm i -D esbuild@0.24.0

@wisnunugroho21

This comment was marked as spam.

@huisam
Copy link

huisam commented Dec 20, 2024

please resolve this 🙏 🙏 I've just rollback to vite v5

@wisnunugroho21
Copy link

seems like a bug from esbuild.
esbuild 0.24.1 has a bug.

@yurrko

This comment was marked as spam.

@sapphi-red
Copy link
Member

sapphi-red commented Dec 20, 2024

It seems a change in esbuild 0.24.1 is affecting Vite's config loader: evanw/esbuild#4010

The current workaround is to set overrides in package managers:

@sapphi-red sapphi-red added bug: upstream Bug in a dependency of Vite p5-urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) labels Dec 20, 2024
@om-baji
Copy link

om-baji commented Dec 20, 2024

Downgrade to vite 5

@MeowB
Copy link

MeowB commented Dec 20, 2024

+1, downgraded to vite 5.5.5

@zcodecn
Copy link

zcodecn commented Dec 20, 2024

I encountered the same error today. After changing Vite to version 5.4.11, it worked fine. It seems that version 6.0 is still unstable.

@sameignatovich
Copy link

Looks like fix on the way: evanw/esbuild#4013

@akshaywritescode
Copy link

it because of es build run "npm install -D vite@^5" on your project root, this version have stable esbuild

@Azz-0179
Copy link

npm i -D esbuild@0.24.0

@iamdanajr
Copy link

iamdanajr commented Dec 20, 2024

It seems a change in esbuild 0.24.1 is affecting Vite's config loader: evanw/esbuild#4010

The current workaround is to set pnpm overrides to package.json:

  "pnpm": {
    "overrides": {
      "esbuild": "0.24.0"
    }
  }

You can use npm overrides or yarn resolutions as well.

Thanks, it's seem this is the only fix for now.

@stormmuller
Copy link

The override does not work in a mono repo

@youkewanzi

This comment was marked as spam.

@Arvay

This comment was marked as spam.

@HumboldtK
Copy link

Getting this same error when using terser.

@breizh24
Copy link

On my project this override worked

{
  "name": "Your app",
  "devDependencies": {
    "vite": "^6.0.4",
  },
  "overrides": {
    "vite": {
      "esbuild": "0.24.0"
    }
  },
}

Then delete the node_modules folder and run npm install

@Blankeos
Copy link

Blankeos commented Dec 20, 2024

Idk what made it work for me. I have a different project where Vite 6 works and I don't even get the above errors.

But on another project, it doesn't.

What I did:

# On my project that doesn't work...
rm -rf node_modules
bun install # or npm install
bun dev # it still didn't work. (weird)

# So to compare with the project that actually worked, I basically...
# 1. Committed my current package.json on the project that doesn't work.
# 2. REMOVED all the `dependencies` and `devDependencies` in the project that doesn't work, then replaced it with the `dependencies` and `devDependencies` of the project that works. (It doesn't matter if the packages don't match).
# 3. Then as usual, I did...
rm -rf node_modules
bun install
bun dev # And this time it worked, cool.
# 4. After that, I stashed the current package.json changes. Meaning it will become your current project's non-working package.json. Then as usual, I did this again...
rm -rf node_modules
bun install
bun dev # And it actually worked for the current project.

I can't even explain what happened. But if anyone's pulling their hair and looking for an alternative solution, hope this helps 😐

@losertowinner
Copy link

Same

@urprakashgupta
Copy link

I always need to run - npm i -D esbuild@0.24.0 when i create new react-vite project. Please solve this issue

@iamdanajr
Copy link

Workaround and the cause

It seems a change in esbuild 0.24.1 is affecting Vite's config loader: evanw/esbuild#4010

The current workaround is to set overrides in package managers:

Edited by @sapphi-red

Describe the bug

Screenshot 0006-12-20 at 14 20 15 ### Reproduction pnpm create vite@latest; babel-react

Steps to reproduce

No response

System Info

System:
    OS: macOS 15.0
    CPU: (8) arm64 Apple M1 Pro
    Memory: 144.56 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.3.0 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.9.0 - /usr/local/bin/npm
    pnpm: 9.15.0 - /usr/local/bin/pnpm
    bun: 1.1.28 - ~/.bun/bin/bun
  Browsers:
    Chrome: 131.0.6778.205
    Safari: 18.0
  npmPackages:
    @vitejs/plugin-react: ^4.3.4 => 4.3.4
    vite: ^6.0.3 => 6.0.4

Used Package Manager

pnpm

Logs

No response

Validations

  "bun": {
      "overrides": {
        "esbuild": "0.24.0"
      }
    }

@Vinayak-palya
Copy link

downgrading vite version solves the above issue

@patak-dev
Copy link
Member

vite@6.0.5 is out pinning to esbuild 0.24.0 until @sapphi-red's PR to esbuild is merged and released, you can update to latest vite to fix this issue

@moto69
Copy link

moto69 commented Dec 20, 2024

Thank you very much. I am cured.

@RubTalha
Copy link

@rakuzen25
Copy link

Now that esbuild has released v0.24.2, is it possible to undo #19027?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: upstream Bug in a dependency of Vite p5-urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority)
Projects
None yet
Development

No branches or pull requests