jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
8.37k stars 196 forks source link

Error: libuuid.so.1: cannot open shared object file: No such file or directory #2046

Open RashiqAzhan opened 4 months ago

RashiqAzhan commented 4 months ago

What happened?

node-canvas dependency breaks the entire node project. node index.js is broken.

I tired following the solutions here to install libuuid manually but to no avail.

Terminal Output:

node:internal/modules/cjs/loader:1473
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: libuuid.so.1: cannot open shared object file: No such file or directory
    at Module._extensions..node (node:internal/modules/cjs/loader:1473:18)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (.../canvas_github_issue/node_modules/canvas/lib/bindings.js:3:18)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12) {
  code: 'ERR_DLOPEN_FAILED'
}

Node.js v20.11.1

Expected output:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nOy9Z3BlaX7e93vf98SbI3BxAXQD3Y2O0xN68szOZi43kGJcUpQDXUWJlF2WqlRll1NJH1xOZbssFWWbFCVZtkRKNJeSxWTuape7s9zZMGkndk/nBOAiAzeee096X3846B7yI8s9NcYYT1dX30J3nT7Ae57zz88fDnGIQxziEIc4xCEOcYhDHOIQfyEYg/iw7+EQH018JB6sf/k7v/ol3/P+6fbWdufX/v7/0bm7utHR2qwrKTqkphOhO/3dQWcC60D4Yd/vIQ4OrA/7Bh4ETBq3JU4t7zu12bmph24vr5Nqg5ACqQQ60uDaeIAQbAtBx5Jq3XXtzkyj0vnCj3y88+TzF9aXb691nnr6sY5bHnaeeOJX4g/7+zrEh4+PBEFcqduOJZlIC8/1sJQkSWOSxICAOElRQhAnKQYaUoiG48mHLSXxfJ9KtURvb4gQEmliwl2b/+uf/tfbw8GoUy6VO6Nhv9OcnlnvLHc62zu7nUmsOqt3bq3HhbnOb/zGbxwS6SOMjwRB0vGoJUslPM+mWi2Ry/kEk4g4iVFKoZRECPBcGykFSZoipCDRhna7zdzcLNduLOM4NkoqBIJSqdwo5AsNIcTDtp1dw8/7VE2NXm9AsVRCm4Bf+dkvbCYp63t7g044jjupTjqOLTuWba07edXx7Vxn6JQ7X/nKV9IP++d0iL84PhIE2d7eahcb05QrRZaWFvjuD95ifWsXraFcdImiGC0lSiniJMGxbVKtSZKUQr5EoVAgSWJarXoWlRmD7+cBgzYaz/NRSjFdrzAz3QQpAY1lWQSD0VQYpVO7O92He/0R/e6ASRgxHI5IjWYymVDyIv6Tv/4zm416pfPUM491XM9Zf/vinc6fvnKxs9sddsIw6ChlrZfL04dE+v8YPhIE2RvG7WPSQiqbKNYYnZJzbRCSSiHP1m6PKE5IwhglBUmqwRikFFy9fovBcMDcbIO5dhOdpmig/6+/Te7CaVZ2buK+s8H0Zz4G2zuoIzOYVGNVihihKJZLVCybZrOGEJIoihBSMB6PEUIQjgOUpVjb2JqKEjOVpOZR1wjWNjYZDAMMIISFNoJgPODH/9IXNlOddozRnbXl5U5nZaOTRsl6cRx18qnp9Ig7K9ABzIf9c///Az4SBMkXc23Pz4ExVEo+jjRMV/PYtk2YaHKWoFwqIJXEAFGUorUm1YYwHOHYsHBkhmKphAGMhq9v3eXj6hTr3YCCMdQti1svv81ivcLmP/+/af/0Z7l4/SLVF68gPvsYBT+Hnpsl3x9gH5lB9IbYzTJoUJ5He2YKoRSu6wCwvTtgEsUoywYDe9u75As+lUZ9yhLW1Gg4eHQyDhFK4ZCQEwIlwVg2FSXw8976L/...

The project is working fine inside docker with which the portion shown under expected output was generated.

Steps to reproduce

  1. Get any project that uses node-canvas dependency breaks the entire node project. node index.js is broken.

MWE: index.js

// Source: https://github.com/Automattic/node-canvas?tab=readme-ov-file#quick-example
const { createCanvas, loadImage } = require('canvas')
const canvas = createCanvas(200, 200)
const ctx = canvas.getContext('2d')

// Write "Awesome!"
ctx.font = '30px Impact'
ctx.rotate(0.1)
ctx.fillText('Awesome!', 50, 100)

// Draw line under text
var text = ctx.measureText('Awesome!')
ctx.strokeStyle = 'rgba(0,0,0,0.5)'
ctx.beginPath()
ctx.lineTo(50, 102)
ctx.lineTo(50 + text.width, 102)
ctx.stroke()

// Draw cat with lime helmet
loadImage('https://images-assets.nasa.gov/image/AFRC2024-0067-40/AFRC2024-0067-40~orig.jpg').then((image) => {
  ctx.drawImage(image, 50, 0, 70, 70)

  console.log('<img src="' + canvas.toDataURL() + '" />')
})

package.json

{
  "name": "canvas_github_issue",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "canvas": "^2.11.2"
  }
}

2.1. Devbox route to produce the error.

devbox shell

npm i

node index.js

2.2. Docker route produces no errors.

docker run --rm -it \
      -w /usr/src/app \
      -v .:/usr/src/app \
      node:20.11.1-slim bash

node index.js

Command

shell

devbox.json

{
  "$schema": "https://raw.githubusercontent.com/jetpack-io/devbox/0.10.1/.schema/devbox.schema.json",
  "packages": [
    "nodejs-slim@20.11.1",
    "libuuid@latest"
  ],
  "env": {
    "LD_LIBRARY_PATH": "pkgs.lib.makeLibraryPath [pkgs.libuuid];"
  },
  "shell": {
    "init_hook": ["echo 'Welcome to devbox!' > /dev/null"],
    "scripts": {
      "test": ["echo \"Error: no test specified\" && exit 1"]
    }
  }
}

Devbox version

0.10.5

Nix version

2.18.1

What system does this bug occur on?

Linux (x86-64)

Debug logs

No response

Lagoja commented 4 months ago

I'm having trouble reproducing this exactly, but here are a few suggestions that I think will help:

  1. It looks like the libuuid.so1 file is bundled with the dev output of the libuuid package. You can add this output by running devbox add libuuid --outputs=out,dev

  2. Devbox automatically symlinks any libraries, binaries, and files that it installs to $DEVBOX_PACKAGES_DIR. If you need your node packages to access those libraries, you can try adding export LD_LIBRARY_PATH=$DEVBOX_PACKAGES_DIR/lib:$LD_LIBRARY_PATH to your devbox.json's init_hook. This will ensure that the libraries Devbox installs are in your LD_LIBRARY_PATH while still leaving the rest of LD_LIBRARY_PATH intact

Lagoja commented 4 months ago

Here is an example devbox.json that I got to work on https://devbox.sh:

https://github.com/Lagoja/node-canvas/blob/main/devbox.json

{
  "$schema": "https://raw.githubusercontent.com/jetpack-io/devbox/0.10.1/.schema/devbox.schema.json",
  "packages": {
    "libuuid": {
      "version": "latest",
      "outputs": ["lib"]
    },
    "nodejs":     "20.11",
    "pkg-config": "latest",
    "pixman":     "latest",
    "cairo": {
      "version": "latest",
      "outputs": ["dev"]
    },
    "freetype": {
      "version": "latest"
    },
    "glib": {
      "version": "latest",
      "outputs": ["out"]
    }
  },
  "env": {"LD_LIBRARY_PATH": "$DEVBOX_PACKAGES_DIR/lib"},
  "shell": {
    "init_hook": ["echo 'Welcome to devbox!' > /dev/null"],
    "scripts": {
      "test": ["echo \"Error: no test specified\" && exit 1"]
    }
  }
}
hayeah commented 3 months ago

this solved my problem trying to load zlib when importing numpy.

might it make sense to add LD_LIBRARY_PATH by default if devbox.json doesn't specify one?

0xthierry commented 2 months ago

I tried it on macOS, but it's not working.

Package pangocairo was not found in the pkg-config search path.

Full stack trace:

../canvas@2.11.2/node_modules/canvas install$ node-pre-gyp install --fallback-to-build --update-binary
│ node-pre-gyp info it worked if it ends with ok
│ node-pre-gyp info using node-pre-gyp@1.0.11
│ node-pre-gyp info using node@18.18.2 | darwin | arm64
│ node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v108-darwin-unknown-arm…
│ node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas…
│ node-pre-gyp WARN Pre-built binaries not installable for canvas@2.11.2 and node@18.18.2 (node-v108 ABI, unknown) (falling back to sou…
│ node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canv…
│ gyp info it worked if it ends with ok
│ gyp info using node-gyp@9.4.1
│ gyp info using node@18.18.2 | darwin | arm64
│ gyp info ok 
│ gyp info it worked if it ends with ok
│ gyp info using node-gyp@9.4.1
│ gyp info using node@18.18.2 | darwin | arm64
│ gyp info find Python using Python version 3.11.6 found at "/nix/store/ai4hd8f1xhr0rfjdr17bxx1rwi42sx97-python3-3.11.6/bin/python3"
│ gyp info spawn /nix/store/ai4hd8f1xhr0rfjdr17bxx1rwi42sx97-python3-3.11.6/bin/python3
│ gyp info spawn args [
│ gyp info spawn args   '/nix/store/2wwakb1xdpx14njxrp0s2fxq91q52k42-pnpm-8.10.2/lib/node_modules/pnpm/dist/node_modules/node-gyp/gyp/g…
│ gyp info spawn args   'binding.gyp',
│ gyp info spawn args   '-f',
│ gyp info spawn args   'make',
│ gyp info spawn args   '-I',
│ gyp info spawn args   '/Users/0xthierry/Workspace/Meistrari/tela/node_modules/.pnpm/canvas@2.11.2/node_modules/canvas/build/config.gy…
│ gyp info spawn args   '-I',
│ gyp info spawn args   '/nix/store/2wwakb1xdpx14njxrp0s2fxq91q52k42-pnpm-8.10.2/lib/node_modules/pnpm/dist/node_modules/node-gyp/addon…
│ gyp info spawn args   '-I',
│ gyp info spawn args   '/Users/0xthierry/Library/Caches/node-gyp/18.18.2/include/node/common.gypi',
│ gyp info spawn args   '-Dlibrary=shared_library',
│ gyp info spawn args   '-Dvisibility=default',
│ gyp info spawn args   '-Dnode_root_dir=/Users/0xthierry/Library/Caches/node-gyp/18.18.2',
│ gyp info spawn args   '-Dnode_gyp_dir=/nix/store/2wwakb1xdpx14njxrp0s2fxq91q52k42-pnpm-8.10.2/lib/node_modules/pnpm/dist/node_modules…
│ gyp info spawn args   '-Dnode_lib_file=/Users/0xthierry/Library/Caches/node-gyp/18.18.2/<(target_arch)/node.lib',
│ gyp info spawn args   '-Dmodule_root_dir=/Users/0xthierry/Workspace/Meistrari/tela/node_modules/.pnpm/canvas@2.11.2/node_modules/canv…
│ gyp info spawn args   '-Dnode_engine=v8',
│ gyp info spawn args   '--depth=.',
│ gyp info spawn args   '--no-parallel',
│ gyp info spawn args   '--generator-output',
│ gyp info spawn args   'build',
│ gyp info spawn args   '-Goutput_dir=.'
│ gyp info spawn args ]
│ Package pangocairo was not found in the pkg-config search path.
│ Perhaps you should add the directory containing `pangocairo.pc'
│ to the PKG_CONFIG_PATH environment variable
│ No package 'pangocairo' found
│ gyp: Call to 'pkg-config pangocairo --libs' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
│ gyp ERR! configure error 
│ gyp ERR! stack Error: `gyp` failed with exit code: 1
│ gyp ERR! stack     at ChildProcess.onCpExit (/nix/store/2wwakb1xdpx14njxrp0s2fxq91q52k42-pnpm-8.10.2/lib/node_modules/pnpm/dist/node_…
│ gyp ERR! stack     at ChildProcess.emit (node:events:517:28)
│ gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:292:12)
│ gyp ERR! System Darwin 23.5.0
│ gyp ERR! command "/nix/store/2gs1bzkbap7r4nr7vvyi575mdrj26nby-nodejs-18.18.2/bin/node" "/nix/store/2wwakb1xdpx14njxrp0s2fxq91q52k42-p…
│ gyp ERR! cwd /Users/0xthierry/Workspace/Meistrari/tela/node_modules/.pnpm/canvas@2.11.2/node_modules/canvas
│ gyp ERR! node -v v18.18.2
│ gyp ERR! node-gyp -v v9.4.1
│ gyp ERR! not ok 
│ node-pre-gyp ERR! build error 
│ node-pre-gyp ERR! stack Error: Failed to execute '/nix/store/2gs1bzkbap7r4nr7vvyi575mdrj26nby-nodejs-18.18.2/bin/node /nix/store/2wwa…
│ node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/0xthierry/Workspace/Meistrari/tela/node_modules/.pnpm/@mapbox+node-pr…
│ node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:517:28)
│ node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1098:16)
│ node-pre-gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:303:5)
│ node-pre-gyp ERR! System Darwin 23.5.0
│ node-pre-gyp ERR! command "/nix/store/2gs1bzkbap7r4nr7vvyi575mdrj26nby-nodejs-18.18.2/bin/node" "/Users/0xthierry/Workspace/Meistrari…
│ node-pre-gyp ERR! cwd /Users/0xthierry/Workspace/Meistrari/tela/node_modules/.pnpm/canvas@2.11.2/node_modules/canvas
│ node-pre-gyp ERR! node -v v18.18.2
│ node-pre-gyp ERR! node-pre-gyp -v v1.0.11
│ node-pre-gyp ERR! not ok 
│ Failed to execute '/nix/store/2gs1bzkbap7r4nr7vvyi575mdrj26nby-nodejs-18.18.2/bin/node /nix/store/2wwakb1xdpx14njxrp0s2fxq91q52k42-pn…
└─ Failed in 1.2s at /Users/0xthierry/Workspace/Meistrari/tela/node_modules/.pnpm/canvas@2.11.2/node_modules/canvas
 ELIFECYCLE  Command failed with exit code 1.
Error: error running script "dev:setup-all" in Devbox: exit status 1