-
Notifications
You must be signed in to change notification settings - Fork 40
Closed
Description
Problem
Using runtime dynamic variables in require() calls prevents analysis tools (especially @vercel/nft) from correctly analyzing dependencies, leading to missing files in the build output and runtime errors. (From nitrojs/nitro#3328)
Lines 10 to 26 in 80c4e3f
| let target = currentTarget(); | |
| // Workaround for Bun, which reports a musl target, but really wants glibc... | |
| if (familySync() == GLIBC) { | |
| switch (target) { | |
| case "linux-x64-musl": | |
| target = "linux-x64-gnu"; | |
| break; | |
| case "linux-arm64-musl": | |
| target = "linux-arm64-gnu"; | |
| break; | |
| } | |
| } | |
| // @neon-rs/load doesn't detect arm musl | |
| if (target === "linux-arm-gnueabihf" && familySync() == MUSL) { | |
| target = "linux-arm-musleabihf"; | |
| } | |
| return require(`@libsql/${target}`); |
Reproduction
https://stackblitz.com/edit/github-xs8rw8vq?file=index.js&startScript=start
The @libsql/linux-x64-musl should be included in the file list, but it's not. This is because the dynamic variables mentioned above cause the static analysis to fail to analyze all the required dependencies.
Suggestion
Changing the variable in require to a static string would fix this. I can submit a PR for this 🙌
Metadata
Metadata
Assignees
Labels
No labels