vite: Error: spawn C:\..\node_modules\esbuild\esbuild.exe ENOENT

Describe the bug

npm run build error

System Info

  • vite version: 2.0.0-beta.5
  • Operating System: Windows 10
  • Node version: v15.5.1
  • Optional:
    • npm version: 7.0.9

Logs (Optional if provided reproduction)

$ npm run build --debug

> admin@0.0.0 build
> vite build && mv ../public/_admin/index.html ../resources/views/admin.blade.php

building for production...
node:events:353
      throw er; // Unhandled 'error' event
      ^

Error: spawn C:\Users\Administrator\code\lykee\admin\node_modules\esbuild\esbuild.exe ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:276:19)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:80:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (node:internal/child_process:282:12)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn C:\\Users\\Administrator\\code\\lykee\\admin\\node_modules\\esbuild\\esbuild.exe',
  path: 'C:\\Users\\Administrator\\code\\lykee\\admin\\node_modules\\esbuild\\esbuild.exe',
  spawnargs: [ '--service=0.8.29' ]
}
npm ERR! code 1
npm ERR! path C:\Users\Administrator\code\lykee\admin
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c "vite build && mv ../public/_admin/index.html ../resources/views/admin.blade.php"

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2021-01-05T06_28_01_397Z-debug.log

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (2 by maintainers)

Most upvoted comments

I know how to fix it. Run: node ./node_modules/esbuild/install.js. This should be written in package.json, but the custom package.json does not have this sentence, so you can run it manually.

It turns out npm v7 has a bug that corrupts package-lock.json files: https://github.com/npm/cli/issues/2606. When this happens, packages like esbuild with post install scripts can break. You may be experiencing this bug. A workaround is to delete and recreate your package-lock.json file.

Just run npm install esbuild that’s all