Error: /src/node_modules/isolated-vm/out/isolated_vm.node: invalid ELF header

402 views Asked by At

I have a very simple Dockerfile

FROM emscripten/emsdk

COPY . .
RUN npm install --omit=dev

RUN node index.js

Which the following properties

node --version
v16.20.0
uname -a
Linux buildkitsandbox 6.4.16-linuxkit #1 SMP PREEMPT Wed Oct 25 16:32:24 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

I want to use isolated-vm, I wrote this script

const fs = require("fs");
const ivm = require("isolated-vm");
const isolate = new ivm.Isolate({ memoryLimit: 16 });

const context = isolate.createContextSync();

const jail = context.global;
jail.setSync("global", jail.derefInto());
jail.setSync("log", function (...args) {
  console.log(...args);
});

const hostile = isolate.compileScriptSync("empty");

hostile.run(context).catch((err) => console.error(err));

My package.json

{
  "private": true,
  "dependencies": {
    "isolated-vm": "^4.6.0"
  }
}

When I build the image with the command

docker buildx build --platform linux/amd64 --progress=plain --tag compiler .

I get the error

#11 [7/7] RUN node index.js
#11 0.361 node:internal/modules/cjs/loader:1280
#11 0.361   return process.dlopen(module, path.toNamespacedPath(filename));
#11 0.361                  ^
#11 0.361 
#11 0.361 Error: /src/node_modules/isolated-vm/out/isolated_vm.node: invalid ELF header
#11 0.361     at Object.Module._extensions..node (node:internal/modules/cjs/loader:1280:18)
#11 0.361     at Module.load (node:internal/modules/cjs/loader:1074:32)
#11 0.361     at Function.Module._load (node:internal/modules/cjs/loader:909:12)
#11 0.361     at Module.require (node:internal/modules/cjs/loader:1098:19)
#11 0.361     at require (node:internal/modules/cjs/helpers:108:18)
#11 0.361     at Object.<anonymous> (/src/node_modules/isolated-vm/isolated-vm.js:1:18)
#11 0.361     at Module._compile (node:internal/modules/cjs/loader:1196:14)
#11 0.361     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
#11 0.361     at Module.load (node:internal/modules/cjs/loader:1074:32)
#11 0.361     at Function.Module._load (node:internal/modules/cjs/loader:909:12) {
#11 0.361   code: 'ERR_DLOPEN_FAILED'
#11 0.361 }
#11 ERROR: process "/bin/sh -c node index.js" did not complete successfully: exit code: 1
------
 > [7/7] RUN node index.js:
0.361     at Function.Module._load (node:internal/modules/cjs/loader:909:12)
0.361     at Module.require (node:internal/modules/cjs/loader:1098:19)
0.361     at require (node:internal/modules/cjs/helpers:108:18)
0.361     at Object.<anonymous> (/src/node_modules/isolated-vm/isolated-vm.js:1:18)
0.361     at Module._compile (node:internal/modules/cjs/loader:1196:14)
0.361     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
0.361     at Module.load (node:internal/modules/cjs/loader:1074:32)
0.361     at Function.Module._load (node:internal/modules/cjs/loader:909:12) {
0.361   code: 'ERR_DLOPEN_FAILED'
0.361 }

Is this because my Node.js installation is old?

1

There are 1 answers

1
Rodrigo On

The problem was: I had node_modules in same folder, rming it from filesystem worked.