libsql-js icon indicating copy to clipboard operation
libsql-js copied to clipboard

Dynamic variables in `require` prevents correct dependency analysis

Open kricsleo opened this issue 5 months ago • 0 comments

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 https://github.com/nitrojs/nitro/issues/3328)

https://github.com/tursodatabase/libsql-js/blob/80c4e3fdb0f17e68cce576f68c44aa59d2871d09/index.js#L10-L26

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 🙌

kricsleo avatar Apr 28 '25 14:04 kricsleo