node.jsnpmvite

Cannot install Vite with React, issue seems to be with esbuild


So, I have had this issue for a couple of days now. When I try to build a React Vite project, which I have done countless times, I get this error. Even when I open a completely empty project and try to build a new Vite project this error persists. I am doing everything correctly, npm create vite@latest, then choose React and Javascript, then go to the directory my-vite-project and then run npm i, this pops up.

The issue seems to be that esbuild fails to install for some reason, it seems as if it is open and there is no permission to modify it, I am not sure of that though, what it is trying to do with esbuild. But it is impossible that there is no permission I have tried to run these functions on Windows Powershell with admin mode, on cmd with admin, on VSC with admin and also changed all permission properties to public, and unticked the read-only box. Then I have tried to uninstall the cache for npm and reinstall npm, try different versions of npm, nothing seems to work. Then in VSC, the terminal even crashes sometimes, when i try npm i, but in Powershell I got this error message as well.

npm warn cleanup Failed to remove some directories [
npm warn cleanup   [
npm warn cleanup     'C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules\\array-buffer-byte-length',
npm warn cleanup     [Error: EBUSY: resource busy or locked, rmdir 'C:\Users\rasmu\Desktop\Coding\JS_stuff\testWS\vite-project\node_modules\array-buffer-byte-length'] {
npm warn cleanup       errno: -4082,
npm warn cleanup       code: 'EBUSY',
npm warn cleanup       syscall: 'rmdir',
npm warn cleanup       path: 'C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules\\array-buffer-byte-length'
npm warn cleanup     }
npm warn cleanup   ],
npm warn cleanup   [
npm warn cleanup     'C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules',
npm warn cleanup     [Error: EBUSY: resource busy or locked, rmdir 'C:\Users\rasmu\Desktop\Coding\JS_stuff\testWS\vite-project\node_modules\array-buffer-byte-length'] {
npm warn cleanup       errno: -4082,
npm warn cleanup       code: 'EBUSY',
npm warn cleanup       syscall: 'rmdir',
npm warn cleanup       path: 'C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules\\array-buffer-byte-length'
npm warn cleanup     }
npm warn cleanup   ],
npm warn cleanup   [
npm warn cleanup     'C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules\\@esbuild\\win32-x64',
npm warn cleanup     [Error: EPERM: operation not permitted, unlink 'C:\Users\rasmu\Desktop\Coding\JS_stuff\testWS\vite-project\node_modules\@esbuild\win32-x64\esbuild.exe'] {
npm warn cleanup       errno: -4048,
npm warn cleanup       code: 'EPERM',
npm warn cleanup       syscall: 'unlink',
npm warn cleanup       path: 'C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules\\@esbuild\\win32-x64\\esbuild.exe'
npm warn cleanup     }
npm warn cleanup   ],
npm warn cleanup   [
npm warn cleanup     'C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules\\array.prototype.tosorted',
npm warn cleanup     [Error: EBUSY: resource busy or locked, rmdir 'C:\Users\rasmu\Desktop\Coding\JS_stuff\testWS\vite-project\node_modules\array.prototype.tosorted'] {
npm warn cleanup       errno: -4082,
npm warn cleanup       code: 'EBUSY',
npm warn cleanup       syscall: 'rmdir',
npm warn cleanup       path: 'C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules\\array.prototype.tosorted'
npm warn cleanup     }
npm warn cleanup   ],
npm warn cleanup   [
npm warn cleanup     'C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules\\@esbuild',
npm warn cleanup     [Error: EPERM: operation not permitted, unlink 'C:\Users\rasmu\Desktop\Coding\JS_stuff\testWS\vite-project\node_modules\@esbuild\win32-x64\esbuild.exe'] {
npm warn cleanup       errno: -4048,
npm warn cleanup       code: 'EPERM',
npm warn cleanup       syscall: 'unlink',
npm warn cleanup       path: 'C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules\\@esbuild\\win32-x64\\esbuild.exe'
npm warn cleanup     }
npm warn cleanup   ]
npm warn cleanup ]
npm error code 1
npm error path C:\Users\rasmu\Desktop\Coding\JS_stuff\testWS\vite-project\node_modules\esbuild
npm error command failed
npm error command C:\Windows\system32\cmd.exe /d /s /c node install.js
npm error node:internal/errors:984
npm error   const err = new Error(message);
npm error               ^
npm error
npm error Error: Command failed: C:\Program Files\nodejs\node.exe C:\Users\rasmu\Desktop\Coding\JS_stuff\testWS\vite-project\node_modules\esbuild\bin\esbuild --version
npm error node:child_process:929
npm error     throw err;
npm error     ^
npm error
npm error <ref *1> Error: spawnSync C:\Users\rasmu\Desktop\Coding\JS_stuff\testWS\vite-project\node_modules\@esbuild\win32-x64\esbuild.exe EPERM
npm error     at Object.spawnSync (node:internal/child_process:1124:20)
npm error     at spawnSync (node:child_process:876:24)
npm error     at Object.execFileSync (node:child_process:919:15)
npm error     at Object.<anonymous> (C:\Users\rasmu\Desktop\Coding\JS_stuff\testWS\vite-project\node_modules\esbuild\bin\esbuild:220:28)
npm error     at Module._compile (node:internal/modules/cjs/loader:1358:14)
npm error     at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
npm error     at Module.load (node:internal/modules/cjs/loader:1208:32)
npm error     at Module._load (node:internal/modules/cjs/loader:1024:12)
npm error     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
npm error     at node:internal/main/run_main_module:28:49 {
npm error   errno: -4048,
npm error   code: 'EPERM',
npm error   syscall: 'spawnSync C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules\\@esbuild\\win32-x64\\esbuild.exe',
npm error   path: 'C:\\Users\\rasmu\\Desktop\\Coding\\JS_stuff\\testWS\\vite-project\\node_modules\\@esbuild\\win32-x64\\esbuild.exe',
npm error   spawnargs: [ '--version' ],
npm error   error: [Circular *1],
npm error   status: null,
npm error   signal: null,
npm error   output: null,
npm error   pid: 0,
npm error   stdout: null,
npm error   stderr: null
npm error }
npm error
npm error Node.js v20.14.0
npm error
npm error     at genericNodeError (node:internal/errors:984:15)
npm error     at wrappedFn (node:internal/errors:538:14)
npm error     at checkExecSyncError (node:child_process:890:11)
npm error     at Object.execFileSync (node:child_process:926:15)
npm error     at validateBinaryVersion (C:\Users\rasmu\Desktop\Coding\JS_stuff\testWS\vite-project\node_modules\esbuild\install.js:100:28)
npm error     at C:\Users\rasmu\Desktop\Coding\JS_stuff\testWS\vite-project\node_modules\esbuild\install.js:282:5 {
npm error   status: 1,
npm error   signal: null,
npm error   output: [
npm error     null,
npm error     Buffer(0) [Uint8Array] [],
npm error     Buffer(1363) [Uint8Array] [
npm error       110, 111, 100, 101,  58,  99, 104, 105, 108, 100,  95, 112,
npm error       114, 111,  99, 101, 115, 115,  58,  57,  50,  57,  13,  10,
npm error        32,  32,  32,  32, 116, 104, 114, 111, 119,  32, 101, 114,
npm error       114,  59,  13,  10,  32,  32,  32,  32,  94,  13,  10,  13,
npm error        10,  60, 114, 101, 102,  32,  42,  49,  62,  32,  69, 114,
npm error       114, 111, 114,  58,  32, 115, 112,  97, 119, 110,  83, 121,
npm error       110,  99,  32,  67,  58,  92,  85, 115, 101, 114, 115,  92,
npm error       114,  97, 115, 109, 117,  92,  68, 101, 115, 107, 116, 111,
npm error       112,  92,  67, 111,
npm error       ... 1263 more items
npm error     ]
npm error   ],
npm error   pid: 2964,
npm error   stdout: Buffer(0) [Uint8Array] [],
npm error   stderr: Buffer(1363) [Uint8Array] [
npm error     110, 111, 100, 101,  58,  99, 104, 105, 108, 100,  95, 112,
npm error     114, 111,  99, 101, 115, 115,  58,  57,  50,  57,  13,  10,
npm error      32,  32,  32,  32, 116, 104, 114, 111, 119,  32, 101, 114,
npm error     114,  59,  13,  10,  32,  32,  32,  32,  94,  13,  10,  13,
npm error      10,  60, 114, 101, 102,  32,  42,  49,  62,  32,  69, 114,
npm error     114, 111, 114,  58,  32, 115, 112,  97, 119, 110,  83, 121,
npm error     110,  99,  32,  67,  58,  92,  85, 115, 101, 114, 115,  92,
npm error     114,  97, 115, 109, 117,  92,  68, 101, 115, 107, 116, 111,
npm error     112,  92,  67, 111,
npm error     ... 1263 more items
npm error   ]
npm error }
npm error
npm error Node.js v20.14.0
npm error A complete log of this run can be found in: C:\Users\rasmu\AppData\Local\npm-cache\_logs\2024-12-05T13_24_05_780Z-debug-0.log

The issue has to be with the esbuild file, but I have tried everything, uninstalling node_modules but that's not the issue. Some people suggested that I kill all the node apps running but there seems to be none running, at least I can't find any from task manager. I thought the issue could be with these five files that can't be removed but that's also not the case, I uninstalled them many times, but they change every time.

Please help, I am getting desperate :(


Solution

  • So it turned out that the issue was actually external, after I uninstalled my Avira antivirus, (which was quite annoying!) everything worked like before. So please uninstall your antiviruses like avast, mcafee or Avira, you'll do just fine with Windows defender if you are running Windows.