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

Duplicate native binaries? #21

Closed
brc-dd opened this issue Aug 16, 2023 · 5 comments
Closed

Duplicate native binaries? #21

brc-dd opened this issue Aug 16, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@brc-dd
Copy link

brc-dd commented Aug 16, 2023

Problem

Try https://pkg-size.dev/@swc%2Fcore

It loads @swc/core-linux-x64-musl as well as @swc/core-linux-x64-gnu, wrongly indicating that the package size will be over 100MB while installing locally.

Expected behavior

Only one of those native deps should be loaded (or filtered out) so that the results are aligned to what one would have locally, instead of what one gets on webcontainers. The install size of @swc/core will be less than 50MB.

@brc-dd brc-dd added the bug Something isn't working label Aug 16, 2023
@privatenumber
Copy link
Owner

Thanks for reporting!

The npm install is delegated to Web Containers so it's either a limitation in the environment they mock or a limitation in swc's postinstall script detecting the right distribution to install. I can open a ticket there.

Do you know how swc determines which distribution to install? I took a glance at their postinstall script but it wasn't clear to me: https://unpkg.com/@swc/[email protected]/postinstall.js

@brc-dd
Copy link
Author

brc-dd commented Aug 16, 2023

swc itself doesn't decide which one to install. Each of the prebuilt binaries have os and cpu fields in their package.json (https://docs.npmjs.com/cli/v9/configuring-npm/package-json#os). npm will try to install each optional dep of @swc/core.

Web Containers emulate linux-x64 and both of @swc/core-linux-x64-musl and @swc/core-linux-x64-gnu have the same os+cpu specified. So both get installed.

Locally, the distinction is made on the basis of libc field (musl vs glibc). Web Containers don't support this command (used by npm > detect-libc):

getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true

@privatenumber
Copy link
Owner

Thanks for pointing me in the right direction.

I don't think there's a bug. Just npm on WebContainers is not on v9.6.5: stackblitz/webcontainer-core#1161 (comment)

In the meantime, I can do a pass to remove packages that don't match libc === 'gnu'.

@brc-dd
Copy link
Author

brc-dd commented Aug 16, 2023

Ah, technically the issue is still there with web containers:

image

pnpm v8.6 clearly supports libc field, but it's not able to determine that on web containers. So, yeah, npm version is an issue, but even the compatible versions of other package managers won't work there properly.

@privatenumber
Copy link
Owner

Closing as I fixed this on pkg-size by emulating a gnu environment by enforcing glibc in package.json#libc.

However, some packages like esbuild and lightningcss are installing wasm versions in addition to the Linux distribution so there's still some inaccuracy in terms of what should be getting installed. Seems this is WebContainers interfering to patch certain packages: stackblitz/webcontainer-core#281 (comment) Will file an issue for this.

Regarding your libc bug, I filed an issue here:
stackblitz/webcontainer-core#1162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants