Manual vercel/nft deoptimization for externals
There are edge-cases like #1558 where tree-shaking using nft for externals is not efficient enough and we might miss chunks.
As an escape hatch, we might introduce a manual option to "fully copy" deoptiomized packages
Hey in my tanstack start application I keep getting random module that are missing files and I think its cause nft
- @babel/runtime
- use-sync-external-store
ideally I could just say "include all dist files from all deps"
A few more issues that are NFT not copying all the files
- https://github.com/nitrojs/nitro/issues/3582
- https://github.com/nitrojs/nitro/issues/3581
- https://github.com/nitrojs/nitro/issues/3573
- https://github.com/nitrojs/nitro/issues/3565
@hipstersmoothie we are migrating to nf3 can you please open an issue over there? šš¼ (also feel free to contribute, implementing feature is not that hard, we should introduce an option like fullTraceInclude and recusively scan all package files)
PS: For wasm, experimental.wasm flag is recommanded and for monorepo, we should investigate root cause of current issues.
Started that here https://github.com/unjs/nf3/pull/4 but it could be improved
A few more issues that are NFT not copying all the files
Also Cannot find package knex on production build of nuxt server (api routes) #1496 And Don't bundle a dependency / Incomplete bundle #3668
Did someone have a working solution in the meantime ?
I tried externals options and wasm option wiht no luck.
When running vite build it does not bundle the .output/server/node_modules/.nf3/[email protected]/lib/secp256k1.wasm file
@vafanassieff do you have a reproduction? please try latest v3 nightly.
You do not need to manually specify rules for wasm support (it is bundled by default)
@vafanassieff do you have a reproduction? please try latest v3 nightly.
You do not need to manually specify rules for wasm support (it is bundled by default)
When I'm using nightly I have this error
[vite]: Rollup failed to resolve import "#nitro-internal-pollyfills" from "/Users/afa/code/tanstack-start/cool/node_modules/.pnpm/[email protected][email protected]_@[email protected][email protected][email protected]_rollup@4._phmshmlth7tcdxjiyafiefcbi4/node_modules/nitro/dist/presets/node/runtime/node-server.mjs".
You can have a repro here https://github.com/vafanassieff/nitro-tanstack-start-wasm
Maybe i'm using nightly wrong ?
Thanks for repro @vafanassieff. Correct usage of nightly is like this:
"nitro": "npm:nitro-nightly@latest"
(make sure to remove node_modules and lockfile to avoid stalled deps)
Unfortunately, the upgrade won't just solve issue as tiny-secp256k1 depends on filesystem paths (instead of natively importing .wasm module, analyzable by vite). pg also is not bundler friendly. You can use this workaround in vite config (deployments needs both dependencies to be installed)
environments: {
ssr: {
resolve: {
external: ['tiny-secp256k1', 'pg']
}
},
nitro: {
resolve: {
external: ['tiny-secp256k1', 'pg']
}
},
},