Errors while starting vite + react

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)

New contributor

PanKaJxD is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

Step 1: npm i -D [email protected]

Step 2: npm i

Step 3: npm run dev

2

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

New contributor

Onur Karagül is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

6

Vite 6.0.5 has been released. It fixes this issue by pinning esbuild to v0.24.0 for the time being.

Downgrade with

npm i -D [email protected]

New contributor

Rakshit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

I encountered a similar issue caused by [email protected]. This version seems to have compatibility problems with certain project configurations. The solution I found is to pin the esbuild version to 0.24.0, which works well. You can do this by running:

npm install --save-dev [email protected]

If you’d like to ensure that all your projects use a safe version of esbuild, you can add a dependency resolution in your package.json file:

"devDependencies": {
   ...
   "esbuild": "0.24.0",
   ...
}

Your issue seems to be related to the recent release of esbuild version 0.24.1.

To resolve the issue, downgrade esbuild to a stable version:

npm i -D [email protected]

This should fix the error you are experiencing when running npm run dev.

For more details, see the related GitHub issue: esbuild issue #4012.

A change in esbuild 0.24.1 is affecting Vite’s config loader : https://github.com/evanw/esbuild/issues/4010

pnpm overrides:

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

npm overrides:

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

yarn resolutions:

{
  "resolutions": {
    "esbuild": "0.24.0"
  }
}

By @sapphi-red from git : https://github.com/vitejs/vite/issues/19018#issuecomment-2556490184

Confirmed. Down grading to 5.4.11 solves issue. However, I am able to successfully build some projects with 6.0.4.

package.json:

 "dependencies": {
    "lodash": "4.17.21",
    "lucide-react": "0.468.0"
  },
  "devDependencies": {
    "@vitejs/plugin-react": "4.3.4",
    "vite": "6.0.4"
  },
  "peerDependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "recoil": "^0.7.7",
    "tailwindcss": "^3.3.0"
  }
    $ npm run build

> [email protected] build
> vite build

vite v6.0.4 building for production...
✓ 1592 modules transformed.
dist/index.es.js  63.14 kB │ gzip: 15.92 kB
dist/index.umd.js  43.72 kB │ gzip: 13.77 kB
✓ built in 2.25s

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Errors while starting vite + react

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)

New contributor

PanKaJxD is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

Step 1: npm i -D [email protected]

Step 2: npm i

Step 3: npm run dev

2

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

New contributor

Onur Karagül is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

6

Vite 6.0.5 has been released. It fixes this issue by pinning esbuild to v0.24.0 for the time being.

Downgrade with

npm i -D [email protected]

New contributor

Rakshit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

I encountered a similar issue caused by [email protected]. This version seems to have compatibility problems with certain project configurations. The solution I found is to pin the esbuild version to 0.24.0, which works well. You can do this by running:

npm install --save-dev [email protected]

If you’d like to ensure that all your projects use a safe version of esbuild, you can add a dependency resolution in your package.json file:

"devDependencies": {
   ...
   "esbuild": "0.24.0",
   ...
}

Your issue seems to be related to the recent release of esbuild version 0.24.1.

To resolve the issue, downgrade esbuild to a stable version:

npm i -D [email protected]

This should fix the error you are experiencing when running npm run dev.

For more details, see the related GitHub issue: esbuild issue #4012.

A change in esbuild 0.24.1 is affecting Vite’s config loader : https://github.com/evanw/esbuild/issues/4010

pnpm overrides:

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

npm overrides:

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

yarn resolutions:

{
  "resolutions": {
    "esbuild": "0.24.0"
  }
}

By @sapphi-red from git : https://github.com/vitejs/vite/issues/19018#issuecomment-2556490184

Confirmed. Down grading to 5.4.11 solves issue. However, I am able to successfully build some projects with 6.0.4.

package.json:

 "dependencies": {
    "lodash": "4.17.21",
    "lucide-react": "0.468.0"
  },
  "devDependencies": {
    "@vitejs/plugin-react": "4.3.4",
    "vite": "6.0.4"
  },
  "peerDependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "recoil": "^0.7.7",
    "tailwindcss": "^3.3.0"
  }
    $ npm run build

> [email protected] build
> vite build

vite v6.0.4 building for production...
✓ 1592 modules transformed.
dist/index.es.js  63.14 kB │ gzip: 15.92 kB
dist/index.umd.js  43.72 kB │ gzip: 13.77 kB
✓ built in 2.25s

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật