prebuild / prebuildify-cross

Compile prebuilds in Docker.
17 stars 6 forks source link

npm ERR! canceled #18

Closed kirrg001 closed 6 months ago

kirrg001 commented 7 months ago

Hi there!

I am running into an error. I have tried different images and different node versions.

$ npx prebuildify-cross -i linux-arm64 -t node@14.0.0 --strip prebuildify-cross run ghcr.io/prebuild/linux-arm64:2 prebuildify -t node@14.0.0 --strip --tag-armv

npm ERR! canceled npm ERR! A complete log of this run can be found in: npm ERR! /home/node/.npm/_logs/2024-01-04T21_17_05_957Z-debug-0.log

First of all, it was really hard to get the npm log file out of the docker container. I had to add remove: false to the dockerRun command.

This is the npm log from the container:

0 verbose cli /usr/bin/node /usr/lib/node_modules/npm/bin/npm-cli.js
1 info using npm@8.19.2
2 info using node@v18.12.1
3 timing npm:load:whichnode Completed in 1ms
4 timing config:load:defaults Completed in 4ms
5 timing config:load:file:/usr/lib/node_modules/npm/npmrc Completed in 5ms
6 timing config:load:builtin Completed in 6ms
7 timing config:load:cli Completed in 4ms
8 timing config:load:env Completed in 1ms
9 timing config:load:file:/home/node/app/.npmrc Completed in 0ms
10 timing config:load:project Completed in 23ms
11 timing config:load:file:/home/node/.npmrc Completed in 0ms
12 timing config:load:user Completed in 2ms
13 timing config:load:file:/usr/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 1ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:credentials Completed in 2ms
17 timing config:load:setEnvs Completed in 3ms
18 timing config:load Completed in 47ms
19 timing npm:load:configload Completed in 48ms
20 timing npm:load:mkdirpcache Completed in 5ms
21 timing npm:load:mkdirplogs Completed in 2ms
22 verbose title npm exec prebuildify -t node@14.0.0 --strip --tag-armv
23 verbose argv "exec" "--yes" "false" "--" "prebuildify" "-t" "node@14.0.0" "--strip" "--tag-armv"
24 timing npm:load:setTitle Completed in 4ms
25 timing config:load:flatten Completed in 10ms
26 timing npm:load:display Completed in 14ms
27 verbose logfile logs-max:10 dir:/home/node/.npm/_logs
28 verbose logfile /home/node/.npm/_logs/2024-01-04T21_17_05_957Z-debug-0.log
29 timing npm:load:logFile Completed in 16ms
30 timing npm:load:timers Completed in 1ms
31 timing npm:load:configScope Completed in 0ms
32 timing npm:load Completed in 92ms
33 silly logfile done cleaning log files
34 timing arborist:ctor Completed in 3ms
35 http fetch GET 200 https://registry.npmjs.org/prebuildify 277ms (cache miss)
36 timing arborist:ctor Completed in 0ms
37 timing arborist:ctor Completed in 0ms
38 timing command:exec Completed in 723ms
39 verbose stack Error: canceled
39 verbose stack     at exec (/usr/lib/node_modules/npm/node_modules/libnpmexec/lib/index.js:230:17)
39 verbose stack     at async module.exports (/usr/lib/node_modules/npm/lib/cli.js:78:5)
40 verbose cwd /home/node/app
41 verbose Linux 6.1.57-0-virt
42 verbose node v18.12.1
43 verbose npm  v8.19.2
44 error canceled
45 verbose exit 1
46 timing npm Completed in 967ms
47 verbose code 1
48 error A complete log of this run can be found in:
48 error     /home/node/.npm/_logs/2024-01-04T21_17_05_957Z-debug-0.lo

The log file is not really helpful. I don't know why it's failing. It looks to me that the prebuildify command in the container is failing but I don't know why. Any help would be appreciated :)

I am able to generate prebuilds with latest version of prebuildify on my macbook without any issues.

$ node -v v18.14.2

$ npx prebuildify-cross 5.0.0

Darwin x64

Thank you!

vweevers commented 7 months ago

Did you run npm install --save-dev prebuildify node-gyp prebuildify-cross?

The Error: canceled error comes from https://github.com/npm/cli/blob/v8.19.2/workspaces/libnpmexec/lib/index.js#L230 and got an improved message in a later version of npm: https://github.com/npm/cli/commit/02c7ddb4501682c9e84b8c1325638b7db1ca7deb. It indicates that dependencies are missing.

kirrg001 commented 7 months ago

I installed the dependencies you have mentioned in the root of my lerna project and in the package itself. Both does not work. The problem is that npm workspaces installs them on the root node_modules folder. I guess that's why a dependency cannot be found.

vweevers commented 7 months ago

I see. Yeah, that scenario is not supported by prebuildify-cross. It can only mount one node_modules folder in the Docker container, and expects all dependencies to be there.

kirrg001 commented 7 months ago

Would you accept a pull request? I can take a look

vweevers commented 7 months ago

What solution do you suggest?

kirrg001 commented 7 months ago

I would add a second volume which overrides the node_modules folder.

    const child = dockerRun(image, {
      entrypoint: 'node',
      argv: ['-'].concat(argv),
      remove: false,
      volumes: {
        // Should but can't use :ro (mafintosh/docker-run#12)
        [cygwin(cwd)]: '/input',
        [path.join(cwd, '..', '..', 'node_modules')]: '/input/node_modules'
      },
      env: {
        PREBUILDIFY_CROSS_FILES: files,
        // Disable npm update check
        NO_UPDATE_NOTIFIER: 'true'
      }
    })

If you pass an argv argument e.g. --node-modules-path /absolute/path/to/node_modules we will add the second volume, otherwise by default there is only one volume.

vweevers commented 7 months ago

Sounds good! PR welcome.