nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Manual vercel/nft deoptimization for externals

Open pi0 opened this issue 2 years ago • 10 comments

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

pi0 avatar Dec 07 '23 11:12 pi0

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

hipstersmoothie avatar Oct 06 '25 06:10 hipstersmoothie

ideally I could just say "include all dist files from all deps"

hipstersmoothie avatar Oct 06 '25 08:10 hipstersmoothie

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 avatar Oct 06 '25 18:10 hipstersmoothie

@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.

pi0 avatar Oct 06 '25 19:10 pi0

Started that here https://github.com/unjs/nf3/pull/4 but it could be improved

hipstersmoothie avatar Oct 06 '25 19:10 hipstersmoothie

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 avatar Dec 08 '25 09:12 vafanassieff

@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)

pi0 avatar Dec 08 '25 11:12 pi0

@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 ?

vafanassieff avatar Dec 08 '25 13:12 vafanassieff

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']
      }
    },
  },

pi0 avatar Dec 08 '25 14:12 pi0