yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.37k stars 1.1k forks source link

[Bug?]: Unable to install the `raspi-i2c` package on raspberry pi (but it installs with npm) #6174

Open vajahath opened 6 months ago

vajahath commented 6 months ago

Self-service

Describe the bug

The raspi-i2c has a post install script, in which, the script requires a package ini-builder. Yarn 4 is unable to resolve this ini-builder package even though it is specified in the package.json file of raspi-i2c.

With npm, it works.

To reproduce

Demonstrates the failure (this is executed inside raspberry pi):

pi@raspberrypi:~/Desktop/projects $ mkdir test

pi@raspberrypi:~/Desktop/projects $ cd test

pi@raspberrypi:~/Desktop/projects/test $ yarn init -2
➤ YN0000: · Yarn 4.1.1
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done in 0s 495ms

pi@raspberrypi:~/Desktop/projects/test $ yarn set version stable
➤ YN0000: Done in 0s 25ms

pi@raspberrypi:~/Desktop/projects/test $ yarn install
➤ YN0000: · Yarn 4.1.1
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done in 0s 479ms

pi@raspberrypi:~/Desktop/projects/test $ yarn add raspi-i2c
➤ YN0000: · Yarn 4.1.1
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + raspi-i2c@npm:6.2.4, @isaacs/cliui@npm:8.0.2, @npmcli/agent@npm:2.2.1, @npmcli/fs@npm:3.1.0, and 97 more.
➤ YN0000: └ Completed in 3s 69ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed in 0s 330ms
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ i2c-bus@npm:5.2.3 must be built because it never has been before or the last one failed
➤ YN0007: │ raspi-i2c@npm:6.2.4 must be built because it never has been before or the last one failed
➤ YN0009: │ raspi-i2c@npm:6.2.4 couldn't be built successfully (exit code 1, logs can be found here: /tmp/xfs-49d51910/build.log)
➤ YN0000: └ Completed in 25s 607ms
➤ YN0000: · Failed with errors in 29s 325ms

pi@raspberrypi:~/Desktop/projects/test $ cat /tmp/xfs-49d51910/build.log
# This file contains the result of Yarn building a package (raspi-i2c@npm:6.2.4)
# Script name: postinstall

Enabling I2C at boot time, you may be asked for your password
node:internal/modules/cjs/loader:1137
  throw err;
  ^

Error: Cannot find module 'ini-builder'
Require stack:
- /home/pi/Desktop/projects/test/.yarn/unplugged/raspi-i2c-npm-6.2.4-51f7bc8830/node_modules/raspi-i2c/script/enable_i2c.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15)
    at Module._load (node:internal/modules/cjs/loader:975:27)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/home/pi/Desktop/projects/test/.yarn/unplugged/raspi-i2c-npm-6.2.4-51f7bc8830/node_modules/raspi-i2c/script/enable_i2c.js:34:18)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Module._load (node:internal/modules/cjs/loader:1013:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/pi/Desktop/projects/test/.yarn/unplugged/raspi-i2c-npm-6.2.4-51f7bc8830/node_modules/raspi-i2c/script/enable_i2c.js'
  ]
}

Node.js v18.19.1

The same - I can install with npm

pi@raspberrypi:~/Desktop/projects $ mkdir test-npm
pi@raspberrypi:~/Desktop/projects $ cd test-npm/
pi@raspberrypi:~/Desktop/projects/test-npm $ npm -v
10.5.0
pi@raspberrypi:~/Desktop/projects/test-npm $ node -v
v18.19.1
pi@raspberrypi:~/Desktop/projects/test-npm $ npm init -y
Wrote to /home/pi/Desktop/projects/test-npm/package.json:

{
  "name": "test-npm",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

pi@raspberrypi:~/Desktop/projects/test-npm $ npm i raspi-i2c

added 10 packages, and audited 11 packages in 32s

found 0 vulnerabilities
pi@raspberrypi:~/Desktop/projects/test-npm $

I tried explicitly adding the ini-builder before adding raspi-i2c. Still it does not work:

pi@raspberrypi:~/Desktop/projects $ mkdir test-2
pi@raspberrypi:~/Desktop/projects $ cd test-2
pi@raspberrypi:~/Desktop/projects/test-2 $ yarn init -2
➤ YN0000: · Yarn 4.1.1
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done in 0s 522ms
pi@raspberrypi:~/Desktop/projects/test-2 $ yarn set version stable
➤ YN0000: Done in 0s 25ms
pi@raspberrypi:~/Desktop/projects/test-2 $ yarn add ini-builder
➤ YN0000: · Yarn 4.1.1
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + ini-builder@npm:1.1.1
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed in 0s 236ms
➤ YN0000: · Done in 0s 615ms
pi@raspberrypi:~/Desktop/projects/test-2 $ yarn add raspi-i2c
➤ YN0000: · Yarn 4.1.1
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + raspi-i2c@npm:6.2.4, @isaacs/cliui@npm:8.0.2, @npmcli/agent@npm:2.2.1, @npmcli/fs@npm:3.1.0, @pkgjs/parseargs@npm:0.11.0, abbrev@npm:2.0.0, agent-base@npm:7.1.0, and 93 more.
➤ YN0000: └ Completed in 7s 907ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed in 0s 426ms
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ i2c-bus@npm:5.2.3 must be built because it never has been before or the last one failed
➤ YN0007: │ raspi-i2c@npm:6.2.4 must be built because it never has been before or the last one failed
➤ YN0009: │ raspi-i2c@npm:6.2.4 couldn't be built successfully (exit code 1, logs can be found here: /tmp/xfs-4c89e3d4/build.log)
➤ YN0000: └ Completed in 25s 864ms
➤ YN0000: · Failed with errors in 34s 516ms
pi@raspberrypi:~/Desktop/projects/test-2 $ cat /tmp/xfs-4c89e3d4/build.log
# This file contains the result of Yarn building a package (raspi-i2c@npm:6.2.4)
# Script name: postinstall

Enabling I2C at boot time, you may be asked for your password
node:internal/modules/cjs/loader:1137
  throw err;
  ^

Error: Cannot find module 'ini-builder'
Require stack:
- /home/pi/Desktop/projects/test-2/.yarn/unplugged/raspi-i2c-npm-6.2.4-51f7bc8830/node_modules/raspi-i2c/script/enable_i2c.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15)
    at Module._load (node:internal/modules/cjs/loader:975:27)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/home/pi/Desktop/projects/test-2/.yarn/unplugged/raspi-i2c-npm-6.2.4-51f7bc8830/node_modules/raspi-i2c/script/enable_i2c.js:34:18)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Module._load (node:internal/modules/cjs/loader:1013:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/pi/Desktop/projects/test-2/.yarn/unplugged/raspi-i2c-npm-6.2.4-51f7bc8830/node_modules/raspi-i2c/script/enable_i2c.js'
  ]
}

Node.js v18.19.1

Environment

System:
    OS: Linux 6.6 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (4) arm64 Cortex-A53
  Binaries:
    Node: 18.19.1 - /tmp/xfs-434ceb55/node
    Yarn: 4.1.1 - /tmp/xfs-434ceb55/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v18.19.1/bin/npm

Additional context

Any workaround is appreciated for the time being. But a real fix is much more appreciated.

Let me know if you need any further info.

vajahath commented 6 months ago

What I ended up doing is yarn patch raspi-i2c to remove the post install script - but then executed it myself after installation. Wired - but worked. I don't consider this as a solution. In my case I was lucky that the post install script was updating a system setting. Once it is updated, not needed unless it is a new system.

adding logs here:

pi@raspberrypi:~/Desktop/projects/pi-room $ yarn patch raspi-i2c
➤ YN0000: Package raspi-i2c@npm:6.2.4 got extracted with success!
➤ YN0000: You can now edit the following folder: /tmp/xfs-f88bc8ee/user
➤ YN0000: Once you are done run yarn patch-commit -s /tmp/xfs-f88bc8ee/user and Yarn will store a patchfile based on your changes.
➤ YN0000: Done in 0s 312ms
pi@raspberrypi:~/Desktop/projects/pi-room $ nano /tmp/xfs-f88bc8ee/user/package.json 
<I removed the post install script>

pi@raspberrypi:~/Desktop/projects/pi-room $ yarn patch-commit -s /tmp/xfs-f88bc8ee/user
pi@raspberrypi:~/Desktop/projects/pi-room $ yarn install
➤ YN0000: · Yarn 4.1.1
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + raspi-i2c@patch:raspi-i2c@npm%3A6.2.4#~/.yarn/patches/raspi-i2c-npm-6.2.4-51f7bc8830.patch::version=6.2.4&hash=beac24
➤ YN0000: └ Completed in 0s 454ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ A package was added to the project (+ 55.45 KiB).
➤ YN0000: └ Completed in 1s 66ms
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed in 0s 509ms
➤ YN0000: · Done with warnings in 2s 457ms
pi@raspberrypi:~/Desktop/projects/pi-room $