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

Is it possible to transpile the lib? #660

Closed
nbusser opened this issue Apr 19, 2023 · 10 comments
Closed

Is it possible to transpile the lib? #660

nbusser opened this issue Apr 19, 2023 · 10 comments

Comments

@nbusser
Copy link

nbusser commented Apr 19, 2023

Hi,

I'm using a mac M1 and I want to build the lib for a linux system (AWS lambda).

When I install the package on my computer, I have the following file-tree:
file tree

When running the lambda on AWS, I have the following error message:
logs

I conclude that npm build script builded a specific version for my architecture.
Is it then possible to transpile the lib for another architecture ?

@nbusser nbusser changed the title Is it possible to transpile program? Is it possible to transpile the lib? Apr 19, 2023
@nbusser
Copy link
Author

nbusser commented Apr 19, 2023

As a workaround, I used this lambda layer, which contains the lib properly compiled for AWS lambda execution environment.

@ShivamJoker
Copy link
Contributor

@nbusser since it uses the binary which is compiled, you will have to use the layers or copy the node modules.
You need to ignore the lib while compiling.

@nbusser
Copy link
Author

nbusser commented Apr 19, 2023

@ShivamJoker I added the lib in my builder's (esbuild) externals.
I registered your layer in my serverless function and everything seems to work correctly!

@ShivamJoker
Copy link
Contributor

That's great. I think you can close the issue now, since there is no other way to use it.

@nbusser
Copy link
Author

nbusser commented Apr 19, 2023

Don't you think it is possible to somehow transpile the library to produce a linux build?

I'm thinking of using some shady npm arguments or stuff.

@ShivamJoker
Copy link
Contributor

You can't compile a compiled binary.

Ideally npm packages contain mostly js and CSS which the transpiler understands.

At the end the library is just executing the binary when you call the API via js.

@nbusser
Copy link
Author

nbusser commented Apr 19, 2023

Ok I now understand what you mean, makes sense!

However, there should be one different binary for each architecture.
Then, is there a way to tell npm to install ("setup") the js lib to use the linux x86 binary instead of the binary tailored for my specific system?

@ShivamJoker
Copy link
Contributor

I think there are some flags which you can use, but the best way to get it is by installing it in a system where you'll be running eg. Amazon linux 2.

@Brooooooklyn
Copy link
Owner

Brooooooklyn commented Apr 20, 2023

@nbusser see npm/rfcs#519 (comment)

yarn 1.x can use --ignore-platform flag to download ignore all conditions.
yarn 2+ can use supportedArchitectures to download specified platforms dependencies.
pnpm can use --force flag to download ignore all conditions.

@juaoose
Copy link

juaoose commented Nov 14, 2023

Hijacking this since I defaulted to the layer. In "theory", something like npm install --no-save --arch=x86 --platform=linux ... would work if done from CI? Or am I not understanding?

Thanks for the lib :)

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