balena-io / balena-cli

The official balena CLI tool.
Apache License 2.0
455 stars 143 forks source link

npm install fails on node v16 #2403

Closed tmigone closed 3 months ago

tmigone commented 2 years ago

I'm aware we don't support node v16 yet, just documenting the error which seems to be the same as #2219 and #2221:

~ npm install balena-cli --production --unsafe-perm
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'balena-cli@12.55.2',
npm WARN EBADENGINE   required: { node: '>=10.20.0 <13.0.0', npm: '<7.0.0' },
npm WARN EBADENGINE   current: { node: 'v16.13.1', npm: '8.1.2' }
npm WARN EBADENGINE }
npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /usr/local/Cellar/node@16/16.13.1/libexec/node /usr/local/Cellar/node@16/16.13.1/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/Users/tomi/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! > resin-discoverable-services@1.2.2 prepublish
npm ERR! > npm test && npm run build
npm ERR!
npm ERR!
npm ERR! > resin-discoverable-services@1.2.2 test
npm ERR! > npm run lint && gulp test
npm ERR!
npm ERR!
npm ERR! > resin-discoverable-services@1.2.2 lint
npm ERR! > resin-lint lib tests gulpfile.coffee
npm ERR!
npm ERR!   ⚡ lib/discoverable.coffee
npm ERR!      ⚡ #345: Variable "publishedServices" is assigned to but never read.
npm ERR!   ⚡ tests/discovery.spec.coffee
npm ERR!      ⚡ #11: Variable "be" is assigned to but never read.
npm ERR!   ✓ gulpfile.coffee
npm ERR!
npm ERR! ⚡ Warning! » 0 errors and 2 warnings in 3 files
npm ERR!
npm ERR! [12:28:46] Requiring external module coffeescript/register
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN ERESOLVE overriding peer dependency
npm ERR! npm WARN While resolving: chai-string@1.5.0
npm ERR! npm WARN Found: chai@3.5.0
npm ERR! npm WARN node_modules/chai
npm ERR! npm WARN   dev chai@"^3.5.0" from the root project
npm ERR! npm WARN   5 more (chai-as-promised, mochainon, chai-as-promised, ...)
npm ERR! npm WARN
npm ERR! npm WARN Could not resolve dependency:
npm ERR! npm WARN peer chai@"^4.1.2" from chai-string@1.5.0
npm ERR! npm WARN node_modules/chai-string
npm ERR! npm WARN   chai-string@"^1.1.2" from mochainon@1.0.0
npm ERR! npm WARN   node_modules/mochainon
npm ERR! npm WARN
npm ERR! npm WARN Conflicting peer dependency: chai@4.3.4
npm ERR! npm WARN node_modules/chai
npm ERR! npm WARN   peer chai@"^4.1.2" from chai-string@1.5.0
npm ERR! npm WARN   node_modules/chai-string
npm ERR! npm WARN     chai-string@"^1.1.2" from mochainon@1.0.0
npm ERR! npm WARN     node_modules/mochainon
npm ERR! npm WARN deprecated natives@1.1.6: This module relies on Node.js's internals and will break at some point. Do not use it, and update to graceful-fs@4.x.
npm ERR! npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm ERR! npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm ERR! npm WARN deprecated graceful-fs@1.2.3: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm ERR! npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm ERR! npm WARN deprecated json3@3.3.2: Please use the native JSON object instead of JSON 3
npm ERR! npm WARN deprecated formatio@1.1.1: This package is unmaintained. Use @sinonjs/formatio instead
npm ERR! npm WARN deprecated samsam@1.1.2: This package has been deprecated in favour of @sinonjs/samsam
npm ERR! npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm ERR! npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm ERR! npm WARN deprecated resin-lint@1.5.7: resin-lint is deprecated, please use @balena/lint instead
npm ERR! npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm ERR! npm WARN deprecated coffee-script@1.11.1: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm ERR! npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! fs.js:47
npm ERR! } = primordials;
npm ERR!     ^
npm ERR!
npm ERR! ReferenceError: primordials is not defined
npm ERR!     at fs.js:47:5
npm ERR!     at req_ (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/natives/index.js:143:24)
npm ERR!     at Object.req [as require] (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/natives/index.js:55:10)
npm ERR!     at Object.<anonymous> (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/graceful-fs/fs.js:1:37)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR!     at Module.load (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1005:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:102:18)
npm ERR!     at Object.<anonymous> (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/graceful-fs/graceful-fs.js:3:27)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR!     at Module.load (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1005:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:102:18)
npm ERR!     at Object.<anonymous> (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js:3:10)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR!     at Module.load (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1005:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:102:18)
npm ERR!     at Object.<anonymous> (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/vinyl-fs/lib/src/getContents/index.js:6:18)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR!     at Module.load (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1005:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:102:18)
npm ERR!     at Object.<anonymous> (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/vinyl-fs/lib/src/index.js:8:19)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR!     at Module.load (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1005:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:102:18)
npm ERR!     at Object.<anonymous> (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/vinyl-fs/index.js:4:8)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR!     at Module.load (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1005:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:102:18)
npm ERR!     at Object.<anonymous> (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/gulp/index.js:7:11)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR!     at Module.load (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1005:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:102:18)
npm ERR!     at Object.<anonymous> (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/gulpfile.coffee:1:8)
npm ERR!     at Object.<anonymous> (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/gulpfile.coffee:1:1)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.loadFile (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/coffeescript/lib/coffee-script/register.js:16:19)
npm ERR!     at Module.load (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1005:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:102:18)
npm ERR!     at Liftoff.handleArguments (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/gulp/bin/gulp.js:116:3)
npm ERR!     at Liftoff.execute (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/liftoff/index.js:203:12)
npm ERR!     at module.exports (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/flagged-respawn/index.js:51:3)
npm ERR!     at Liftoff.<anonymous> (/Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/liftoff/index.js:195:5)
npm ERR!     at /Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/liftoff/index.js:165:9
npm ERR!     at /Users/tomi/.npm/_cacache/tmp/git-clonebq31N4/node_modules/v8flags/index.js:93:14
npm ERR!     at FSReqCallback.oncomplete (node:fs:188:23)
npm ERR!
npm ERR! npm ERR! code 1
npm ERR! npm ERR! path /Users/tomi/.npm/_cacache/tmp/git-clonebq31N4
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c npm test && npm run build
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /Users/tomi/.npm/_logs/2021-12-09T15_28_46_676Z-debug.log

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/tomi/.npm/_logs/2021-12-09T15_28_49_817Z-debug.log
jellyfish-bot commented 2 years ago

[tmigone] This issue has attached support thread https://jel.ly.fish/0f7063a5-c30a-4970-b4ab-9cd3499749ee

hpgmiskin commented 2 years ago

We use the Balena CLI for downloading and creating device images (thus only a very small part of the functionality). There are ways to install Balena CLI on Node 16, but this install has not been tested on any of the functionality. We were using Node 16.13.1 and NPM 8.19.1.

The main change which allowed installation was overriding/resolving graceful-fs to ^4.2.10, as per How to fix "ReferenceError: primordials is not defined" in Node.js - Stack Overflow. This is enough to get the installation working using npm install --ignore-scripts. If using yarn (which for this particular installation we are not) you will also need to install with --ignore-engines, however, there might be other issues.

I never managed to get the installation working in CI/CD without using --ignore-scripts due to a combination of errors with patch-package. On my local I got around them by directly modifying package-lock.json in order to prevent patch-package from being hoisted from node_modules/balena-cli/node_modules to node_modules.

patch-package was hoisted during NPM install so not accessible to postinstall ``` npm ERR! code 1 npm ERR! path /home/runner/work/hackhub-config/hackhub-config/node_modules/balena-cli npm ERR! command failed npm ERR! command sh /tmp/postinstall-9a2bfb65.sh npm ERR! Applying patches from "patches/all"... npm ERR! Failed to apply some patches: npm ERR! Error: Command failed: node node_modules/patch-package/index.js --patch-dir patches/all npm ERR! node:internal/modules/cjs/loader:959 npm ERR! throw err; npm ERR! ^ npm ERR! npm ERR! Error: Cannot find module '/home/runner/work/hackhub-config/hackhub-config/node_modules/balena-cli/node_modules/patch-package/index.js' npm ERR! at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15) npm ERR! at Function.Module._load (node:internal/modules/cjs/loader:804:27) npm ERR! at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:[12](https://github.com/mytosbio/hackhub-config/runs/8230553881?check_suite_focus=true#step:4:13)) npm ERR! at node:internal/main/run_main_module:[17](https://github.com/mytosbio/hackhub-config/runs/8230553881?check_suite_focus=true#step:4:18):47 { npm ERR! code: 'MODULE_NOT_FOUND', npm ERR! requireStack: [] npm ERR! } ```
patch-package does not work with nested production dependencies ``` npm ERR! code 1 npm ERR! path /home/runner/work/hackhub-config/hackhub-config/node_modules/balena-cli npm ERR! command failed npm ERR! command sh -c -- node patches/apply-patches.js npm ERR! Applying patches from "patches/all"... npm ERR! Failed to apply some patches: npm ERR! Error: Command failed: node node_modules/patch-package/index.js --patch-dir patches/all npm ERR! Error: Patch file found for package config which is not present at node_modules/@oclif/config npm ERR! Error: Patch file found for package parser which is not present at node_modules/@oclif/parser npm ERR! Error: Patch file found for package plugin-help which is not present at node_modules/@oclif/plugin-help npm ERR! Error: Patch file found for package exit-hook which is not present at node_modules/exit-hook npm ERR! Error: Patch file found for package oclif which is not present at node_modules/oclif npm ERR! Error: Patch file found for package open which is not present at node_modules/open npm ERR! Error: Patch file found for package opn which is not present at node_modules/opn npm ERR! --- npm ERR! patch-package finished with 7 error(s). ```

Both of the above issues seem closely related to https://github.com/ds300/patch-package/issues/84

myarmolinsky commented 3 months ago

Closing as we now require node >= 20.6.0