Closed rdzidziguri closed 5 months ago
The problem:
__dirname
magic variable.__dirname
is the folder of the bundle rather than the folder of sodium-native's "index.js", so it can't find the native library binary.The hack I'm currently using: add --external:sodium-native
to the ESBuild command line.
The downside of that hack is that sodium-native's JS code is no longer part of the ESBuild bundle. It will be require
'd at runtime, so the bundle is no longer self-contained. You need to include the sodium-native library with your deployment, e.g. in "node_modules".
The ESBuild issue tracker has some examples of how to use an ESBuild plugin to fake out the __dirname
magic variable to refer to the location of the original file: https://github.com/evanw/esbuild/issues/859. I haven't tried it out.
I have used https://github.com/martonlederer/esbuild-plugin-fileloc to get a build working locally (one of the solutions mentioned in that thread).
Have not tried in lambda
I know this uses native modules and probably needs to be treated differently; however, I do not have much experience with native modules. I can easily handle layers, but the use case and problem I am facing is that whenever I try to use the EsBuild bundler and either run it locally on Windows 11 or AWS Lambda, I get the following
No native build was found for platform
error. could someone advise or even confirm if running the package on AWS Lambda is feasible at all? environment is Node18