14

I'm encountering an error while trying to install the npm package "esbuild" in a Docker build process. The build was working fine previously, and I haven't made any significant changes recently. However, the build now fails with the following error message:

 => ERROR [stage-0 5/6] RUN npm install                                                                                                                                                                                                                                          6.6s
------
 > [stage-0 5/6] RUN npm install:
#0 6.440 npm notice 
#0 6.440 npm notice New minor version of npm available! 9.6.7 -> 9.7.1
#0 6.440 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.7.1>
#0 6.440 npm notice Run `npm install -g npm@9.7.1` to update!
#0 6.440 npm notice 
#0 6.441 npm ERR! code 1
#0 6.441 npm ERR! path /app/node_modules/esbuild
#0 6.441 npm ERR! command failed
#0 6.441 npm ERR! command sh -c node install.js
#0 6.442 npm ERR! node:internal/errors:496
#0 6.442 npm ERR!     ErrorCaptureStackTrace(err);
#0 6.442 npm ERR!     ^
#0 6.442 npm ERR! 
#0 6.442 npm ERR! <ref *1> Error: spawnSync /app/node_modules/esbuild/bin/esbuild ETXTBSY
#0 6.442 npm ERR!     at Object.spawnSync (node:internal/child_process:1117:20)
#0 6.442 npm ERR!     at spawnSync (node:child_process:871:24)
#0 6.442 npm ERR!     at Object.execFileSync (node:child_process:914:15)
#0 6.442 npm ERR!     at validateBinaryVersion (/app/node_modules/esbuild/install.js:98:28)
#0 6.442 npm ERR!     at /app/node_modules/esbuild/install.js:285:5 {
#0 6.442 npm ERR!   errno: -26,
#0 6.442 npm ERR!   code: 'ETXTBSY',
#0 6.442 npm ERR!   syscall: 'spawnSync /app/node_modules/esbuild/bin/esbuild',
#0 6.442 npm ERR!   path: '/app/node_modules/esbuild/bin/esbuild',
#0 6.442 npm ERR!   spawnargs: [ '--version' ],
#0 6.442 npm ERR!   error: [Circular *1],
#0 6.442 npm ERR!   status: null,
#0 6.442 npm ERR!   signal: null,
#0 6.442 npm ERR!   output: null,
#0 6.442 npm ERR!   pid: 0,
#0 6.442 npm ERR!   stdout: null,
#0 6.443 npm ERR!   stderr: null
#0 6.443 npm ERR! }
#0 6.443 npm ERR! 
#0 6.443 npm ERR! Node.js v20.3.0
#0 6.443 
#0 6.443 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-06-13T03_18_04_432Z-debug-0.log

I tried clearing the Docker cache and removing any linked node_modules directory but the problem persists. I can reproduce this locally and in CI.

Federico B.
  • 941
  • 8
  • 19
  • After regenerating the `package-lock.json` file, npm removed `esbuild` entries for several other architectures in the lockfile and the problem disappeared. The only remaining entry left is for darwin-arm64 which corresponds to my host computer arch but not the one which Docker would use. I haven't found the root cause for why the additional entries triggered the error so I am leaving the question open for now. – Federico B. Jun 14 '23 at 20:55
  • Same issue here. We are not using Windows or Vagrant. We are building in GCP. Impossible to reproduce this error locally. Impossible to fix it as we actually need esbuild – bny Jun 15 '23 at 10:16

3 Answers3

8

I was using node:20.3.0-bullseye-slim as a base image and fixed the issue by rollbacking to a previous version (node:20.2.0-bullseye-slim).

QuiiBz
  • 81
  • 1
  • 3
0

Try to write the version of the image in the dockerfile It helped me

FROM --platform=linux/amd64 node:19.5.0
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Maksim
  • 9
  • 1
0

I had encountered the same error

I'm using node:20.3-alpine3.18 but i didn't want to rollback to a different version because it was running on any other machine.

16.96 npm ERR! <ref *1> Error: spawnSync /app/node_modules/esbuild/bin/esbuild ETXTBSY
...
npm ERR!   errno: -26,
npm ERR!   code: 'ETXTBSY',
npm ERR!   syscall: 'spawnSync /app/node_modules/esbuild/bin/esbuild',
npm ERR!   path: '/app/node_modules/esbuild/bin/esbuild',
...

However, I had some features from Docker Desktop activated, including 'Use Rosetta for x86/amd64 emulation...' on my M1 Mac.

I decided to disable the 'Use Rosetta' option in Docker Desktop. After disabling 'Use Rosetta for x86/amd64 emulation...', I rebuilt my Docker container, and the build process ran smoothly without any file locking issues. My npm packages were installed correctly, and the project is up and running again. I hope this solution proves beneficial to anyone encountering a similar issue.

Docker Desktop Use Rosetta location

Manuel Spigolon
  • 11,003
  • 5
  • 50
  • 73
4ddev
  • 1
  • 1