Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No native build was found - EsBuild AWS Lambda #184

Closed
rdzidziguri opened this issue Jul 15, 2023 · 2 comments
Closed

No native build was found - EsBuild AWS Lambda #184

rdzidziguri opened this issue Jul 15, 2023 · 2 comments

Comments

@rdzidziguri
Copy link

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

@cakoose
Copy link

cakoose commented Sep 16, 2023

The problem:

  1. Normally, sodium-native looks for the native library binary in a location relative to sodium-native's "index.js" file by using the __dirname magic variable.
  2. When ESBuild bundles things, it inlines sodium-native's "index.js" into the bundle.
  3. When the bundle runs, __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: evanw/esbuild#859. I haven't tried it out.

@mixmix
Copy link
Contributor

mixmix commented Oct 5, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants