IPX provider only works with override of `sharp` dependency on linux-arm64
Hello,
first of all I am not sure if this is a bug in nuxt-image, ipx, sharp, bun or another package so please let me know if this is the wrong repo for the report.
I just updated to nuxt-image v2.0.0 and only can get it to work with IPX as a provider if I use the "overrides" field in package.json to pin a specific version of the sharp dependency. If I don't use the override field and let the dependencies be resolved automatically I get the following response if I load an image in my nuxt app:
[500] [IPX_ERROR] Could not load the \"sharp\" module using the linux-arm64 runtime
ERR_DLOPEN_FAILED: libstdc++.so.6: cannot open shared object file: No such file or directory
After some debugging I think the main problem is the used version of the detect-libc sub dependency. Here is the diff between the two lockfiles (a/bun.lock = no override, broken; b/bun.lock = override, works):
diff --git a/bun.lock b/bun.lock
index a90531fd..bf0f82cf 100644
--- a/bun.lock
+++ b/bun.lock
@@ -52,6 +52,7 @@
},
"overrides": {
"archiver": "^7.0.1",
+ "sharp": "0.34.5",
"unzipper": "^0.12.3",
"vite": "npm:[email protected]",
},
@@ -1312,7 +1313,7 @@
- "detect-libc": ["[email protected]", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="],
+ "detect-libc": ["[email protected]", "", { "bin": { "detect-libc": "./bin/detect-libc.js" } }, "sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg=="],
@@ -2490,6 +2491,8 @@
+ "@mapbox/node-pre-gyp/detect-libc": ["[email protected]", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="],
@@ -2520,8 +2523,6 @@
- "@parcel/watcher/detect-libc": ["[email protected]", "", { "bin": { "detect-libc": "./bin/detect-libc.js" } }, "sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg=="],
@@ -2642,6 +2643,8 @@
+ "lightningcss/detect-libc": ["[email protected]", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="],
@@ -2690,6 +2693,8 @@
+ "sharp/detect-libc": ["[email protected]", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="],
The sharp/detect-libc is only installed if I use the sharp version override which maybe causes the issue?
Additional Info
- I don't know for sure if the bug was introduced in v2.0.0 of nuxt-image, since I was using a sharp override before as well due to #1908
- The issue only occurs on the deployment server that uses linux-arm64. Locally on darwin in works fine
output of ldding the sharp-binary
sharp v0.34.5 (no override) ❌
# ldd .output/server/node_modules/@img/sharp-linux-arm64/lib/sharp-linux-arm64.node
linux-vdso.so.1 (0x0000e199b2a25000)
libvips-cpp.so.8.17.3 => /app/.output/server/node_modules/@img/sharp-linux-arm64/lib/../../sharp-libvips-linux-arm64/lib/libvips-cpp.so.8.17.3 (0x0000e199b1710000)
libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000e199b1480000)
libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000e199b13d0000)
libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000e199b1390000)
libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000e199b1360000)
libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000e199b11a0000)
/lib/ld-linux-aarch64.so.1 (0x0000e199b29e8000)
libresolv.so.2 => /lib/aarch64-linux-gnu/libresolv.so.2 (0x0000e199b1170000)
libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000e199b1140000)
sharp v0.34.5 (via override) ✅
# ldd .output/server/node_modules/@img/sharp-linux-arm64/lib/sharp-linux-arm64.node
linux-vdso.so.1 (0x0000f2e10cd6b000)
libvips-cpp.so.8.17.3 => /app/.output/server/node_modules/@img/sharp-linux-arm64/lib/../../sharp-libvips-linux-arm64/lib/libvips-cpp.so.8.17.3 (0x0000f2e10ba50000)
libstdc++.so.6 => /nix/store/zmjqwzhgl9hwr8xnk8raj8d50lzkql66-gcc-14.3.0-lib/lib/libstdc++.so.6 (0x0000f2e10b7e0000)
libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000f2e10b730000)
libgcc_s.so.1 => /nix/store/zmjqwzhgl9hwr8xnk8raj8d50lzkql66-gcc-14.3.0-lib/lib/libgcc_s.so.1 (0x0000f2e10b6f0000)
libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000f2e10b6c0000)
libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000f2e10b500000)
/lib/ld-linux-aarch64.so.1 (0x0000f2e10cd2e000)
libresolv.so.2 => /lib/aarch64-linux-gnu/libresolv.so.2 (0x0000f2e10b4d0000)
libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000f2e10b4a0000)
Probably related to #1372 and #1210, but slightly different due to the error pointing to libstdc++.so.6 now. Is pinning the dependency still the recommended solution or should this work in v2.0.0?
I get a different error:
{
"error": {
"message": "[500] [IPX_ERROR] Cannot find module '../data/patch.json'\nRequire stack:\n- /root/XXX/apps/XXX/.output/server/node_modules/.nitro/[email protected]/lib/data-patch.js"
}
}
ldd .output/server/node_modules/@img/sharp-linux-x64/lib/sharp-linux-x64.node
linux-vdso.so.1 (0x00007ffff17f9000)
libvips-cpp.so.8.17.3 => /root/XXX/apps/YYY/.output/server/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/libvips-cpp.so.8.17.3 (0x00007e3f2fa00000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007e3f2f600000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007e3f2f917000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007e3f30c1d000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007e3f30c18000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007e3f2f200000)
/lib64/ld-linux-x86-64.so.2 (0x00007e3f30cbd000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007e3f30c05000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007e3f2f912000)
I get a different error:
{ "error": { "message": "[500] [IPX_ERROR] Cannot find module '../data/patch.json'\nRequire stack:\n- /root/XXX/apps/XXX/.output/server/node_modules/.nitro/[email protected]/lib/data-patch.js" } }
I also struggled with this error before. In the end I needed to manually patch the css-tree dependency myself, as described here https://github.com/oven-sh/bun/issues/13076#issuecomment-2451515462 (using the patch feature instead of writing directly to the package cache). Unfortunately two different versions of css-tree were in my dependency tree, so I needed to apply the same patch to v2.2.1 and v3.1.0. There are some more potential workarounds in this issue, but those did not work for me: https://github.com/csstree/csstree/issues/314
Encountered the same issue: “Cannot find module '../data/patch.json'” after updating to version 2.0.0.
I get a different error:
{ "error": { "message": "[500] [IPX_ERROR] Cannot find module '../data/patch.json'\nRequire stack:\n- /root/XXX/apps/XXX/.output/server/node_modules/.nitro/[email protected]/lib/data-patch.js" } }ldd .output/server/node_modules/@img/sharp-linux-x64/lib/sharp-linux-x64.node linux-vdso.so.1 (0x00007ffff17f9000) libvips-cpp.so.8.17.3 => /root/XXX/apps/YYY/.output/server/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/libvips-cpp.so.8.17.3 (0x00007e3f2fa00000) libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007e3f2f600000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007e3f2f917000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007e3f30c1d000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007e3f30c18000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007e3f2f200000) /lib64/ld-linux-x86-64.so.2 (0x00007e3f30cbd000) libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007e3f30c05000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007e3f2f912000)
Looks like the same as #1967
Same here
{"error":{"message":"[500] [IPX_ERROR] Cannot find module '../data/patch.json'\nRequire stack:\n- /srv/webapp/server/node_modules/.nitro/[[email protected]](vscode-file://vscode-app/c:/Users/Nicolae/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html)/lib/data-patch.js"}}
Same issue here too after updating
[500] [IPX_ERROR] Cannot find module '../data/patch.json'
Require stack:
- /app/.output/server/node_modules/.nitro/[email protected]/lib/data-patch.js
I’ve successfully found a workaround using a patch file.
This example uses pnpm patch, but the same approach should work with patch-package or a similar tool.
This works on node v24, in v22 and below the imports look probably a bit different.
pnpm patch css-tree
diff --git a/lib/data-patch.js b/lib/data-patch.js
index cd49cbec3e7de20dea750e95e007dbdb1488ac96..35aa442909868315ffeeab2903e14e4bfb19f374 100644
--- a/lib/data-patch.js
+++ b/lib/data-patch.js
@@ -1,6 +1,3 @@
-import { createRequire } from 'module';
-
-const require = createRequire(import.meta.url);
-const patch = require('../data/patch.json');
+import patch from "../data/patch.json" with { type: "json" };
export default patch;
diff --git a/lib/data.js b/lib/data.js
index 162fa2068f45413e415e22ad1fe56f4c372623ad..717bde1806d2efa46a1ec27fe1f00481bba2aaa1 100755
--- a/lib/data.js
+++ b/lib/data.js
@@ -1,10 +1,9 @@
import { createRequire } from 'module';
import patch from './data-patch.js';
-const require = createRequire(import.meta.url);
-const mdnAtrules = require('mdn-data/css/at-rules.json');
-const mdnProperties = require('mdn-data/css/properties.json');
-const mdnSyntaxes = require('mdn-data/css/syntaxes.json');
+import mdnAtrules from 'mdn-data/css/at-rules.json' with { type: "json" };
+import mdnProperties from 'mdn-data/css/properties.json' with { type: "json" };
+import mdnSyntaxes from 'mdn-data/css/syntaxes.json' with { type: "json" };
const hasOwn = Object.hasOwn || ((object, property) => Object.prototype.hasOwnProperty.call(object, property));
const extendSyntax = /^\s*\|\s*/;
diff --git a/lib/version.js b/lib/version.js
index dde3a83f43883ecbad6ca0a23afb58c12235148a..2488683b6215eaee0a44983d9e784371e81cbe7d 100644
--- a/lib/version.js
+++ b/lib/version.js
@@ -1,5 +1,3 @@
-import { createRequire } from 'module';
+import pkg from "../package.json" with { type: "json" };
-const require = createRequire(import.meta.url);
-
-export const { version } = require('../package.json');
+export const version = pkg.version;
This worked for me (yarn):
package.json:
"resolutions": {
"css-tree": "2.2.1"
}
nuxt.config.ts:
nitro: {
externals: {
traceInclude: [
'node_modules/css-tree/data/patch.json',
]
}
},