Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Native modules support #69

Closed
ehmicky opened this issue Nov 6, 2019 · 8 comments
Closed

Native modules support #69

ehmicky opened this issue Nov 6, 2019 · 8 comments

Comments

@ehmicky
Copy link
Contributor

ehmicky commented Nov 6, 2019

Native modules must be built and run on the same OS. Our build system runs on Linux and so do our AWS Lambda functions. However there are several posts that describe a bigger setup to get any native modules working on AWS Lambda. Do we support native modules on Netlify Functions?

Also they must also be built and run on the same Node.js version. Otherwise they show some error message when run. Our build system uses the NODE_VERSION environment variable or .nvmrc file, with a default of Node 10.*.*. However our AWS Lambda functions use the AWS_LAMBDA_JS_RUNTIME environment variable, with a default of Node 8.10.0. Note that Node.js version is not relevant when using N-API but not all native modules are using this yet.

@DavidWells
Copy link
Contributor

Right now its BYO native modules.

E.g. if you want to use headless chrome in a function you need to include the precompiled binary as a dependancy.

There are some projects in the broader ecosystem that are working to solve this binary issue. One is called "yumda" described here https://www.serverlesschats.com/19

There are a couple of ways users can include precompiled binaries:

  • Built it themselves locally with amazon lambda linux distro
  • Use a precompiled version on npm
  • Use custom lambda layers (not supported in netlify right now)
  • Use a custom runtime (not supported in netlify right now)

Use a precompiled version on npm is the easiest from DX point of view

@ehmicky
Copy link
Contributor Author

ehmicky commented Nov 6, 2019

Thanks for this response.

So this means at the moment zip-it-and-ship-it does not support native modules, correct? This is quite a limitation. We have some users reporting it right now.

Now I have tried myself on a Netlify Site to use a Function file using node-sqlite (which is a native module) and it worked just fine. I am not sure why.

@DavidWells
Copy link
Contributor

Users with native modules that don't just work via default zip-ship need to manually build there own functions right now.

It is not ideal.

This is why the @netlify/build functions building/packaging is overridable.

Functions revamp is needed and will happen one day ™

@ehmicky
Copy link
Contributor Author

ehmicky commented Nov 6, 2019

It is not ideal.

Yes it's a major limitation. Having native modules somewhere in the dependencies tree is quite common in production apps.

@ehmicky
Copy link
Contributor Author

ehmicky commented Nov 7, 2019

It looks native modules are in fact supported by zip-it-and-ship-it, kind of. This user made it work with node-sqlite which is a native module. I also made it work myself as noted above.

It seems like building native modules against other Linuxes might work when run on Amazon Linux. However NODE_VERSION and AWS_LAMBDA_JS_RUNTIME need to match the same Node.js version. This later restriction might not apply to native modules that use N-API.

@ehmicky ehmicky transferred this issue from netlify/build Nov 7, 2019
@ehmicky ehmicky changed the title Native modules inside Netlify Functions Native modules support Nov 7, 2019
@ehmicky
Copy link
Contributor Author

ehmicky commented Apr 27, 2020

Note: this issue is being reported in #79 as well.

@eduardoboucas
Copy link
Member

@ehmicky I don't think there's anything more that zip-it-and-ship-it specifically can do about native module support right now. Since #433, it returns a list of any native modules it finds, so that CLI can warn users when deploying locally.

Do you think we can close this one, or do you have anything else in mind?

@ehmicky
Copy link
Contributor Author

ehmicky commented Aug 23, 2021

👍

@ehmicky ehmicky closed this as completed Aug 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants