laverdet / isolated-vm

Secure & isolated JS environments for nodejs
ISC License
2.12k stars 151 forks source link

Error: /lowcode/node_modules/isolated-vm/out/isolated_vm.node: invalid ELF header #484

Closed rakeshar3796 closed 2 months ago

rakeshar3796 commented 2 months ago

Is Your Question Already Answered?

Personal Diagnostics

Please answer the following questions:

JavaScript includes a setTimeout function:

Functions are a type of primitive value in JavaScript:

Objects can be shared between isolates:

The Code

Am facing the below issue in Docker, i tried ignoring node_modules in my .dockerignore as mentioned here

Error: /lowcode/node_modules/isolated-vm/out/isolated_vm.node: invalid ELF header
at Module._extensions..node (node:internal/modules/cjs/loader:1460:18)
at Module.load (node:internal/modules/cjs/loader:1203:32)
at Module._load (node:internal/modules/cjs/loader:1019:12)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:177:18)
at Object.<anonymous> (/lowcode/node_modules/isolated-vm/isolated-vm.js:1:18)
at Module._compile (node:internal/modules/cjs/loader:1364:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
at Module.load (node:internal/modules/cjs/loader:1203:32)
at Module._load (node:internal/modules/cjs/loader:1019:12) {
code: 'ERR_DLOPEN_FAILED'

If my file has below snippet, am seeing the above error during docker up, if i remove that its running fine. My node version is 18 and even tried v20.

const ivm = require("isolated-vm");
laverdet commented 2 months ago

You need to run npm install from inside the container, not outside. And ignore node_modules.

https://www.docker.com/blog/getting-started-with-docker-using-node-jspart-i/

COPY package.json package.json COPY package-lock.json package-lock.json RUN npm install

rakeshar3796 commented 2 months ago

Got that, was trying the same earlier and now found the root cause, volume mount is causing the issue, resolved. Thanks for the prompt response! Appreciated.