[Feature] Reduce duplicate package copies in the npm-resolved install (about 10 MB, mostly @ai-sdk and undici)
Summary
A clean npm install of the published package installs many packages more than once. The biggest groups are @ai-sdk/provider-utils (3 versions, 4 copies), @ai-sdk/provider (4 copies) and undici (3 versions). Users resolve with npm from our version ranges, not from pnpm-lock.yaml, so the lock file does not prevent this.
Steps to reproduce
npm pack --ignore-scripts --pack-destination /tmp/pack- In an empty folder:
npm init -y && npm install /tmp/pack/nanocollective-nanocoder-1.31.0.tgz --ignore-scripts npm ls @ai-sdk/provider-utils @ai-sdk/provider undici
Expected behaviour
One copy of each shared package where the version ranges allow it.
Actual behaviour
@ai-sdk/[email protected] -> @ai-sdk/[email protected] -> [email protected]
@ai-sdk/[email protected] -> @ai-sdk/[email protected]
[email protected] -> @ai-sdk/[email protected], @ai-sdk/gateway -> @ai-sdk/[email protected]
@nanocollective/[email protected] -> cheerio -> [email protected]
nanocoder itself -> [email protected]
Total of the npm-resolved tree: 366 packages, 234 MB, of which 29 package names are installed more than once and about 9.9 MB is extra copies (undici 2.1 + 1.6 + 1.2 MB, provider-utils 1.1 + 0.9 + 0.8 + 0.8 MB, entities, parse5, type-fest, iconv-lite and others).
Environment
- OS: Windows 11 (10.0.26300)
- Node: 22.22.3, npm (bundled with Node 22)
- Nanocoder: 1.31.0 (main at be428fc7)
Suggested fix
- Cause:
package.json:81pins@ai-sdk/openai-compatibleto2.0.51and:87pinsaito6.0.193, while the other providers use^, so they resolve to newerprovider-utils. - The pins look intentional (a bump of openai-compatible to 3.0.5 was reverted), so a maintainer should decide: loosen to
~ranges, or raise the carets so oneprovider-utilssatisfies all. - The
overridesfield does not help consumers of the published package. - Check the result with the
npm lscommand above, not only with pnpm.
@addyCooks I'd like to work this, if it's available to claim ?
Hi @addyCooks, I read through #1819–#1828 and they all serve the same goal: a lighter, faster-starting nanocoder, which #1827 ties together. I'd love to work on this with you.
What is your plan for this? I'd say lets do stacked PR
Hi @puri-adityakumar! Thanks for looking into this, I'd prefer keeping this as a single PR rather than stacking.
Here's why:
This issue is pretty straightforward - just updating a few version ranges in package.json to let npm deduplicate packages.
The fix is isolated and doesn't depend on #1819-#1822 or #1824-#1826.
Those other issues are all performance improvements too, but they each tackle different things (lazy loading, async operations, etc.).
Stacking them would add complexity without much benefit here.
#1827 is the one that ties everything together into a --lite preset, but it explicitly says it should be done after the individual fixes exist.
My thinking: Keep each optimization separate so:
- Multiple people can work on different issues in parallel
- Reviews stay focused and easier to merge
- If something breaks, we can revert just that piece
If you want to work on this, I can assign it to you! And once it's done, feel free to pick another issue from the set.
sure please assign this too me