Repository navigation
Closed
Description
Describe the bug
This might be somewhat of a feature request but since there's an error message I'm using the bug template.
To Reproduce
- Start a Docker container with Node.js that is based on Alpine Linux, for example
nodered/node-red:
docker run -it --rm --entrypoint /bin/bash --user root nodered/node-red- Create some test scripts:
cd /
mkdir test
cd test
npm install imagescript
echo "import {Image} from 'imagescript'; const i = new Image(200, 200);" > test.mjs- Run the script:
node test.mjsActual behavior
An error message appears:
# node test.mjs
/test/node_modules/imagescript/codecs/node/index.js:3
catch (err) { throw new Error('unsupported arch/platform: ' + err.message); }
^
Error: unsupported arch/platform: Error loading shared library ld-linux-aarch64.so.1: No such file or directory (needed by /test/node_modules/imagescript/codecs/node/bin/arm64-linux.node)
at Object.<anonymous> (/test/node_modules/imagescript/codecs/node/index.js:3:21)
at Module._compile (node:internal/modules/cjs/loader:1198:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
at Module.load (node:internal/modules/cjs/loader:1076:32)
at Function.Module._load (node:internal/modules/cjs/loader:911:12)
at Module.require (node:internal/modules/cjs/loader:1100:19)
at require (node:internal/modules/cjs/helpers:108:18)
at Object.<anonymous> (/test/node_modules/imagescript/ImageScript.js:4:16)
at Module._compile (node:internal/modules/cjs/loader:1198:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
Expected behavior
Script runs, no output
Platform:
- OS: Linux
- Environment: NodeJS in Docker
- Version: 1.2.16
Additional context
I tried apk add gcompat and apk add libc6-compat. It changes the error message into:
# node test.mjs
/test/node_modules/imagescript/codecs/node/index.js:3
catch (err) { throw new Error('unsupported arch/platform: ' + err.message); }
^
Error: unsupported arch/platform: Error relocating /test/node_modules/imagescript/codecs/node/bin/arm64-linux.node: __memcpy_chk: symbol not found
at Object.<anonymous> (/test/node_modules/imagescript/codecs/node/index.js:3:21)
at Module._compile (node:internal/modules/cjs/loader:1198:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
at Module.load (node:internal/modules/cjs/loader:1076:32)
at Function.Module._load (node:internal/modules/cjs/loader:911:12)
at Module.require (node:internal/modules/cjs/loader:1100:19)
at require (node:internal/modules/cjs/helpers:108:18)
at Object.<anonymous> (/test/node_modules/imagescript/ImageScript.js:4:16)
at Module._compile (node:internal/modules/cjs/loader:1198:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
AndreKR commentedon Aug 15, 2023
I just found out that Node-RED recently introduced Debian-based Docker images, so this isn't an actual concern for me.
wtone commentedon Jul 31, 2025
只要是 docker node:*-alpine 镜像 就会有问题,在Docker node:18-alpine 镜像容器中,新建一个测试脚本
docker run -it --rm node18:alpine sh
mkdir test
cd test
npm init
npm i imagescript sharp
vi test.js
//test.js
const { arch, platform } = require('os');
console.log(arch(), platform())
try {
module.exports = require(
imagescript/codecs/node/bin/${arch()}-${platform()}.node);}catch (err) { throw new Error('unsupported arch/platform: ' + err.message); }
执行就会报错 :Segmentation fault (core dumped)
同样的引用node原生模块,sharp库就不会报错
console.log(platformAndArch())
try {
module.exports = require(
sharp/build/Release/sharp-${platformAndArch()}.node);} catch (err) {
throw new Error('unsupported arch/platform: ' + err.message);
}
比较后,发现主要是因为platform这个变量取值以及Alpine 的 musl libc 兼容性问题,主要原因是:
1、musl 与 glibc 二进制不兼容
.node 文件是 Node.js 原生模块(C/C++ 编译的二进制文件),若该文件是在 glibc 系统(如 Ubuntu、CentOS)上编译的,而 Alpine 使用 musl libc,两者的二进制接口不兼容,会导致 Node.js 无法正确加载模块(即使文件存在)。
2、获取当前运行环境的平台信息的方式有问题:
// imagescript/codecs/node/index.js
const { arch, platform } = require('os');
module.exports = require(
./bin/${arch()}-${platform()}.node);简单通过os.platform获取的值,无法区分linux(Ubuntu、CentOS) 和 linuxmusl(Docker alpine容器),可以参考 sharp库的做法写一个方法来获取platform和arch:
function platformAndArch() {
const arch = env.npm_config_arch || process.arch;
const platform = env.npm_config_platform || process.platform;
const libc = process.env.npm_config_libc ||
/* istanbul ignore next */
(detectLibc.isNonGlibcLinuxSync() ? detectLibc.familySync() : '');
const libcId = platform !== 'linux' || libc === detectLibc.GLIBC ? '' : libc;
}
在Docker alpine 容器中调用platformAndArch()将得到的platform和arch是 “x64-linuxmusl”
3、本身提供的imagescript/codecs/node/bin/*.node 文件中也没有包含支持x64-linuxmusl.node的文件
需要重新编译一份适配linuxmusl的模块文件(x64-linuxmusl.node),并添加到imagescript/codecs/node/bin/目录下。
matmen commentedon Oct 14, 2026
Fixed in 3.0.0: ImageScript no longer ships any WebAssembly or native binaries. Every codec is plain TypeScript, so there’s nothing to load, bundle or compile per platform, and it runs on Alpine/musl, in bundled serverless functions, Deno, Bun and browsers. npm install imagescript@3; see the changelog for breaking changes.