Pkg: ABI incompatibility message `RangeError: Index out of range`

Created on 17 May 2017  路  4Comments  路  Source: vercel/pkg

Hi,

I'm trying to use pkg to build a cross-platform executable on MacOS to run on Linux. I'm using the following build command (where myapp is a directory containing a package.json and the relevant js files, etc.):

pkg -o myapp_linux/myapp -t linux myapp

The build works and I don't get any unexpected build errors. When I run the output executable on Linux I get the following runtime error:

buffer.js:842
    throw new RangeError('Index out of range');
          ^

RangeError: Index out of range
    at checkOffset (buffer.js:842:11)
    at Buffer.readInt32LE (buffer.js:995:5)
    at evalmachine.<anonymous>:0:0
    at evalmachine.<anonymous>:0:0
    at Object.Module._extensions..node (evalmachine.<anonymous>:0:0)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at Module.require (evalmachine.<anonymous>:0:0)

Can anyone please help to resolve this? The cross-platform feature is great and I would really like to use it.

Some notes:

  • Replacing "-t linux" with "-t mac" successfully creates a mac version which runs fine on MacOS.
  • Running the node app directly on linux using node works fine with the same source.
  • Using pkg to build on the Linux machine, with the same build command, produces a successful output (this is my backup if I can't get the cross-platform build to work, but I would rather not do this if possible).
  • The processor architecture of both the Mac and Linux machines is x86_64 (as output by "uname -m")
  • "file myapp" on the output displays the following:
yoidserver: ELF 64-bit LSB  executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, BuildID[sha1]=bfc575652f6dcc5ba1920e786c4102954056a46f, not stripped
bug patch

All 4 comments

Index out of range is the key. It is weird error that means that native addon (.node file) being required is not ABI-compatible with node.js runtime inside executable. npm uses system-wide node.js to build native addons. You need to be sure that your system-wide node.js version on target linux machine (at the moment you run npm install and make .node files) - is exactly the same version you specify in -t option. Please note that -t linux takes node.js version from system-wide of compilation macos machine. You probably need to specify -t node7-linux explicitly as well.

That sorted it! Thanks very much. My Mac is running node7, but the Linux system is running node6. I specified -t node6-linux and it worked perfectly.

Happy to close this.

Great! :tada: I suggest renaming the issue and reopening it.

Stumbled upon this myself!

Any way we can change the message?

A native addon (.node file) is not compatible with the target node.js version. You probably need to specify the same node.js target version used to compile the addon or recompile the addon with a matching version.

Was this page helpful?
0 / 5 - 0 ratings