Closed brc-dd closed 1 year ago
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/core@1.3.77/postinstall.js
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
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: https://github.com/stackblitz/webcontainer-core/issues/1161#issuecomment-1680695661
In the meantime, I can do a pass to remove packages that don't match libc === 'gnu'
.
Ah, technically the issue is still there with web containers:
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.
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: https://github.com/stackblitz/webcontainer-core/issues/281#issuecomment-894768040 Will file an issue for this.
Regarding your libc bug, I filed an issue here: https://github.com/stackblitz/webcontainer-core/issues/1162
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.