mmomtchev / node-gdal-async

Node.js bindings for GDAL (Geospatial Data Abstraction Library) with full async support
https://mmomtchev.github.io/node-gdal-async/
Apache License 2.0
129 stars 26 forks source link

Unknown application error occurred Runtime.ImportModuleError: AWS Lambda #102

Closed JustinFokes closed 11 months ago

JustinFokes commented 11 months ago

Hello and thanks for the library!

I'm trying to run in a Lambda with Node 18, and am getting the following error:

Error: Cannot find module '/var/task/node_modules/gdal-async/lib/binding/node-v108-linux-x64/gdal.node'",

I am not seeing node-v108-linux-x64 in the output of my node_modules (at least locally), but do see: node-v115-darwin-x64.

Did I miss a step, or have I missed something larger? I can get this to work locally just fine, but Lambda chokes.

I am using: "gdal-async": "^3.7.1",

Thanks for any pointers!

mmomtchev commented 11 months ago

This module automatically downloads the right binary for you platform, so this is normal. Otherwise this issue looks a lot like #99, can you check?

JustinFokes commented 11 months ago

Not sure about that issue, but, your comment did point me in another direction.

My node version locally which I am building and zipping for the lambda was node 20. So I changed that to node version 18.

There is still a difference from what I can tell between x-linux-x64 on Lambda, and x-darwin-x64 which is being outputted in my zip.

mmomtchev commented 11 months ago

You can't transfer node_modules between platforms, you must install on each platform.

JustinFokes commented 11 months ago

So, if gdal creates bindings during install, and I am running macos, and Lambda is running Linux, that's the problem? If so, any workaround for that?

mmomtchev commented 11 months ago

Normally, a node_modules should only be used on the host where it was created and should not be copied around. But in practice, you can copy it if the target host has the same version of Node.js and it is running the same operating system.

If you don't have access to a Linux machine, you can download the Linux binary manually to produce a node_modules that works on both macOS and Linux, but you are on your own with this approach.

cd node_modules/gdal-async
npx node-pre-gyp reinstall

You will see where it gets the binary from. Get it from https://github.com/mmomtchev/node-gdal-async/releases/download/v3.7.1/node-v108-linux-x64.tar.gz and untar it manually.

JustinFokes commented 11 months ago

Unfortunately, Lambda uses a zip file created on my mac. I will try this approach. Thank you for the pointers and help!