Automattic / Automattic/node-canvas

when install using npm 8.x, node-gyp rebuild runs instead of node-pre-gyp, so prebuilt binaries are not downloaded

Open
#2,082 10 comments 12 reactions 0 assignees View on GitHub
Installation help
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

## Issue or Feature
- [x] If this is an issue with installation, I have read the [troubleshooting guide](https://github.com/Automattic/node-canvas/issues/1511).

When using npm 6, the install runs `node-pre-gyp` to download prebuilt binaries as expected and the install is successful.

When using npm 8, the install runs `node-gyp` which attempts to rebuild the binaries and the install fails because pkg-config is not available.

We want to download the prebuilt binaries, not rebuild them. What is needed to have `node-pre-gyp` run with npm 8?

## Steps to Reproduce

App package.json contains only canvas as a dependency to make it as simple as possible:
```
"dependencies": {
"canvas": "^2.9.3"
}
```

Ensure starting from scratch:
`rm -rf node_modules`
`rm package-lock.json`

**npm 6 install successful**: npm install runs `node-pre-gyp install --fallback-to-build --update-binary`
```
npm install --verbose
< lines removed >
npm info lifecycle canvas@2.9.3~install: canvas@2.9.3

> canvas@2.9.3 install /Users/developer/Documents/dev/test/node_modules/canvas
> node-pre-gyp install --fallback-to-build --update-binary

node-pre-gyp info it worked if it ends with ok
node-pre-gyp verb cli [
node-pre-gyp verb cli '/usr/local/bin/node',
node-pre-gyp verb cli '/Users/developer/Documents/dev/test/node_modules/.bin/node-pre-gyp',
node-pre-gyp verb cli 'install',
node-pre-gyp verb cli '--fallback-to-build',
node-pre-gyp verb cli '--update-binary'
node-pre-gyp verb cli ]
node-pre-gyp info using node-pre-gyp@1.0.9
node-pre-gyp info using node@16.16.0 | darwin | x64
node-pre-gyp verb command install []
node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.9.3/canvas-v2.9.3-node-v93-darwin-unknown-x64.tar.gz
node-pre-gyp http download proxy agent configured using: "http://:8000"
node-pre-gyp info install unpacking Release/
< lines removed >
```

**npm 8 install failure**: npm install runs `node-gyp rebulld` instead of `node-pre-gyp install --fallback-to-build --update-binary`:
```
npm install --verbose
< lines removed>
npm timing build:link:node_modules/@mapbox/node-pre-gyp Completed in 5ms
npm timing build:link:node_modules/mkdirp Completed in 4ms
npm timing build:link:node_modules/rimraf Completed in 4ms
npm timing build:link:node_modules/semver Completed in 4ms
npm timing build:link:node_modules/nopt Completed in 5ms
npm timing build:link:node_modules/color-support Completed in 6ms
npm timing build:link:node_modules/make-dir/node_modules/semver Completed in 5ms
npm timing build:link Completed in 6ms
npm info run canvas@2.9.3 install node_modules/canvas node-gyp rebuild
< lines removed >
npm timing command:i Completed in 25221ms
npm verb stack Error: command failed
npm verb stack at ChildProcess. (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:63:27)
npm verb stack at ChildProcess.emit (node:events:527:28)
npm verb stack at maybeClose (node:internal/child_process:1092:16)
npm verb stack at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
npm verb pkgid canvas@2.9.3
npm verb cwd /Users/developer/Documents/dev/test
npm verb Darwin 21.5.0
npm verb node v16.16.0
npm verb npm v8.15.0
npm ERR! code 1
npm ERR! path /Users/developer/Documents/dev/test/node_modules/canvas
npm ERR! command failed
npm ERR! command sh /var/folders/lz/021n8xl50lg7h3qlm0knb1qrgw086n/T/install-f6f99e1b.sh
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli '/usr/local/bin/node',
npm ERR! gyp verb cli '/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js',
npm ERR! gyp verb cli 'rebuild'
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@9.0.0
npm ERR! gyp info using node@16.16.0 | darwin | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
< lines removed>
npm ERR! /bin/sh: pkg-config: command not found
npm ERR! gyp: Call to 'pkg-config pixman-1 --libs' returned exit status 127 while in binding.gyp. while trying to load binding.gyp
npm ERR! gyp ERR! configure error
```

## Your Environment
macOS 12.4
System Darwin 21.5.0
node -v v16.16.0
npm -v 8.15.0
"canvas": "^2.9.3"

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.