evanw/esbuild

Windows Installation Issue with other packages

Opened this issue · 3 comments

This has really stumped me. Pardon if this should be reported in another Github repository, but since I am having specific issue only with this package, I thought as well of reporting here.

In a nutshell, the package @esbuild/win32-x64 fails when it is being installed alongside other packages for an application. In a clean, only @esbuild install, it downloads fine.

This is the scenario I have tested it upon.

Machine OS & Details

  • Windows 11
  • Node 20.11.1
  • npm 10.2.4

React Application

  • Scaffold a new application using Vite with command: npm create vite@latest vite-react-ts -- --template react-ts
  • Navigate inside the vite-react-ts folder
  • Run npm install and I get the following in the console:
    image
  • The file package.json contents are below
{
  "name": "vite-react-ts",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc -b && vite build",
    "lint": "eslint .",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^18.3.1",
    "react-dom": "^18.3.1"
  },
  "devDependencies": {
    "@eslint/js": "^9.15.0",
    "@types/react": "^18.3.12",
    "@types/react-dom": "^18.3.1",
    "@vitejs/plugin-react": "^4.3.4",
    "eslint": "^9.15.0",
    "eslint-plugin-react-hooks": "^5.0.0",
    "eslint-plugin-react-refresh": "^0.4.14",
    "globals": "^15.12.0",
    "typescript": "~5.6.2",
    "typescript-eslint": "^8.15.0",
    "vite": "^6.0.1"
  }
}
  • With the install failing, the folder node_modules is not created

Empty Application

  • Create a folder called empty and navigate inside it
  • Run npm init
  • Accept all default options as presented
    image
  • Install the esbuild package alone via npm i @esbuild/win32-x64
    image
  • Navigate inside the folder node_modules\@esbuild\win32-x64 and list the contents.
    image

Legacy Application (Initialized with Create React App)

  • Trying as well to install @esbuild to an existing application via npm i @esbuild/win32-x64, I get the the folder @esbuild\win32-x64 being created inside node_modules, but the file esbuild.exe is not present
    image

Other Notes

  • I think we can rule out any antivirus blocking the install, as I've been able to install the package in an empty project folder.
  • I also tried to download the binary through the URL https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.24.0.tgz, extracting the esbuild.exe file and attempting to copy it to the folder inside the node_modules folder but get the Access Denied

Has anyone experienced this issue before?

I guess it has some thing to do with your terminal being executed under administrator permission. You can try to use a normal (user) permission terminal to see if it still happens.

I guess it has some thing to do with your terminal being executed under administrator permission. You can try to use a normal (user) permission terminal to see if it still happens.

I did tried using terminal under non-admin permission and still get the same result.

evanw commented

This doesn't look good:

[esbuild] Failed to install package "@esbuild/win32-x64" using npm: EPERM: operation not permitted, rename 'C:\_angelo\zzz\vite-react-ts\node_modules\esbuild\Lib\npm-install\node_modules\@esbuild\win32-x64\esbuild.exe' →> 'C:\_angelo\zzz\vite-react-ts\node_modules\esbuild\Lib\downloaded-@esbuild-win32-x64-esbuild.exe'

First, the fact that esbuild is trying to download itself at all instead of letting npm do it (which I know it's doing since it's renaming a file called downloaded-...-esbuild.exe) means that something about your npm configuration isn't working with optional packages. Normally esbuild installs itself with npm's optional package feature so that npm downloads the appropriate package for your platform automatically. This can happen if you configure your package manager --no-optional or --omit=optional (potentially configured at a global level). Fixing that might fix this install.

Second, the rename syscall failing sounds like an anti-virus issue to me given that it's Windows and a) Windows typically has anti-virus running and b) unlike Unix, Windows doesn't support renaming a file while something is using it. When esbuild downloads itself, it downloads into a temporary file and then renames that file to the destination instead of downloading into the destination to avoid ending up with a partially-downloaded file in the destination (file renaming is an atomic operation). I'm guessing the anti-virus is keeping the file open and preventing it from being moved.

If fixing optional packages doesn't fix this, then I'm not sure how to fix this other than to change something about your anti-virus. This situation is sort of a fundamental flaw with using anti-virus on Windows. Some programs try to get around this by retrying the operation after a delay (hoping that the anti-virus is done messing with the file), but that isn't guaranteed to work either and slows everything else down if the underlying problem is actually a permission issue, so I don't want to do that.