nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Issues with flatten extrernals tracing and multiple versions

Open pi0 opened this issue 1 year ago • 1 comments

On production builds, we trace used package files from node_modules and extract them to .output/server/node_modules but at the same time, flatten the structure by choosing the latest requested version of each package.

This strategy has two major issues:

  1. In the case of two major versions (sub-dependencies)
  2. In the case of two minor versions (eg #259) since we already traced, if the version is not compatible one will fail as we already traced paths back to their actual package path

For solving 1, only possible solution is hoisting sub-dependencies into node_modules/parent/node_modules/child. It can be also done by respecting package manager structure without flattening it or less fragile by doing what package managers do for hosting with more stable output with different pms!

For solving 2, we need to re-trace internal package paths in case of a conflict is detected as external exports and API of a package should be compatible in semver-minor/patch but since we already traced them to internal structure, it will be broken.

pi0 avatar Oct 12 '22 22:10 pi0

I have a Stackblitz example of major version collisions here: https://stackblitz.com/edit/github-1wqbue-kp7mfb?file=composables%2FuseMain.ts,app.vue,package.json

Ignore the dev mode, just step out of it and run npm run build && npm run preview to see the issue.

Let me know if there's anything I can test for you guys!

TheDutchCoder avatar Oct 13 '22 12:10 TheDutchCoder