node-gfx / node-canvas-prebuilt

Repo used to build binaries for node-canvas on CI
169 stars 31 forks source link

npm ci failed with missing node-pre-gyp #50

Closed yiochen closed 6 years ago

yiochen commented 6 years ago

Step to reproduce:

> mkdir test-canvas-prebuilt
> cd test-canvas-prebuilt
> npm init
> npm install canvas-prebuilt
> npm ci

throws error:

npm WARN prepare removing existing node_modules/ before installation

> canvas-prebuilt@1.6.5-prerelease.1 install some-path/node_modules/canvas-prebuilt
> node_modules/.bin/node-pre-gyp install

sh: node_modules/.bin/node-pre-gyp: No such file or directory
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! canvas-prebuilt@1.6.5-prerelease.1 install: `node_modules/.bin/node-pre-gyp install`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the canvas-prebuilt@1.6.5-prerelease.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     some-path/.npm/_logs/2018-08-17T23_32_55_765Z-debug.log

From this, it seems like we need to list node-pre-gyp as bundledDependencies in package.json

node -v 10.3.0 npm -v 6.1.0

chearon commented 6 years ago

Shouldn't having it in dependencies ensure node-pre-gyp is present? It sounds like bundledDependencies copies dependencies into the tarball before publishing, but we shouldn't have to force people to have multiple copies of node-pre-gyp.

zbjornson commented 6 years ago

Yeah, Mapbox doesn't recommend it anymore:

Note: in the past we recommended putting node-pre-gyp in the bundledDependencies, but we no longer recommend this. In the past there were npm bugs (with node versions 0.10.x) that could lead to node-pre-gyp not being available at the right time during install (unless we bundled). This should no longer be the case.

https://github.com/mapbox/node-pre-gyp/blob/master/README.md

yiochen commented 6 years ago

I am also confused. This seems to be an issue with npm ci. I managed to work around it by adding node-pre-gyp to my package.json

chearon commented 6 years ago

Yeah... seems like a bug in npm. Feel free to re-open if you find otherwise.

Pumpuli commented 6 years ago

I think that npm is working as intended and this is actually an issue with canvas-prebuilt. It has been fixed too for over a year, but only in v2 alphas (#13). I wonder if it's possible to backport that fix to the latest tag too?

The isssue is that npm dedupes node-pre-gyp to top-level but the install script of canvas-prebuilt assumes that it's found in its own node_modules folder.

I.e. assumed structure:

project-root
└ node_modules
  └ canvas-prebuilt
    └ node_modules
       └ node-pre-gyp

Actual structure:

project-root
└ node_modules
  ├ canvas-prebuilt
  └ node-pre-gyp
Pumpuli commented 6 years ago

Turns out the install script doesn't work at all on Windows native command line due to it having forward slashed and no quotes. This was of course the original reason for #13, it just also happened to fix the missing node-pre-gyp issue.

@chearon could this fix be backported to latest package too (i.e. version 1.x)?

chearon commented 6 years ago

Yeah sorry, I'll try to do that soon, someone else just asked for it in #51.

lavor commented 6 years ago

Can you publish that 1.6.12 version, please. The npm ci still doesn't work.

chearon commented 6 years ago

Sorry I missed that, it's been difficult supporting 1.x which is an old/broken build and the 2.x series and build.

I pushed the commit @Pumpuli mentioned to the 1.x build branch for the next release. As for a 1.6.12, version of canvas-prebuilt, I screwed that up a while back and unpublished it because it accidentally included canvas as a dependency 🤦‍♂️ so should I:

I'm not sure which is worse

lavor commented 6 years ago

Thank you for your answer, I think the latter is better, but it is just my opinion. I can use 2.x if it is working there, but I see it as alpha version. Is it stable now?

zbjornson commented 6 years ago

There's one known regression in both 2.x and 1.6.12 (https://github.com/Automattic/node-canvas/issues/1249). It has a PR to fix it that needs to be reviewed. Otherwise 2.x is stable.