Conditional subpath with only "import" condition mis-traced — wrong file copied on Vercel deploy
Summary
When a package's exports field declares a subpath whose only conditions are "types" + "import" (no "default", no "require"), nft appears to mis-trace it during Vercel function packaging. At runtime, Node's ESM loader resolves the bare specifier to a different file than the subpath should yield — specifically, it ends up loading the package's main entry instead of the subpath entry — and module instantiation fails because the expected named export is missing.
Repro
Package: @paypal/[email protected].
Its exports map:
{
".": {
"types": "./types/index.d.ts",
"import": "./dist/esm/paypal-js.js",
"require": "./dist/cjs/paypal-js.js"
},
"./sdk-v6": {
"types": "./types/v6/index.d.ts",
"import": "./dist/v6/esm/paypal-js.js"
}
}
The ./sdk-v6 subpath has no default/require condition.
dist/v6/esm/paypal-js.js exports loadCoreSdkScript, version.
dist/esm/paypal-js.js (the . entry) exports loadScript, loadCustomScript, version — no loadCoreSdkScript.
What I did
- React Router v7 (framework mode) app deployed via
@vercel/react-routerpreset. - SSR module statically imports
loadCoreSdkScriptfrom@paypal/paypal-js/sdk-v6. Vite externalizes the package, so the SSR bundle literally containsimport { loadCoreSdkScript } from \"@paypal/paypal-js/sdk-v6\". - Deploy to Vercel (Node 24 runtime).
Expected
Function loads, Node resolves @paypal/paypal-js/sdk-v6 to dist/v6/esm/paypal-js.js, named import loadCoreSdkScript binds successfully.
Actual
Function crashes on instantiation:
SyntaxError: The requested module '@paypal/paypal-js/sdk-v6' does not
provide an export named 'loadCoreSdkScript'
at #asyncInstantiate (node:internal/modules/esm/module_job:319:21)
This is Node's named-export validation failing — the resolved module exists and loads, but doesn't have loadCoreSdkScript. The export shape matches the v5 entry (.), strongly suggesting nft caused the deployed function's resolution to fall through to the main entry instead of the ./sdk-v6 subpath.
Local sanity checks (all pass)
node --input-type=module -e \"import('@paypal/paypal-js/sdk-v6').then(m => console.log(Object.keys(m)))\"→['loadCoreSdkScript', 'version']- Fresh
npm i @paypal/[email protected]in an empty dir + ESM import works. - Same on Node 24.
Hypothesis
When nft walks the package and a subpath lacks "default"/"require" conditions, the trace step misses or drops the v6 file (or the package.json is rewritten such that Node falls back to legacy pkg + subpath.js / main resolution). Either way, the deployed function ends up with the wrong file.
Workaround
Convert the static import to a dynamic await import(\"@paypal/paypal-js/sdk-v6\") inside a client-only code path so nft never has to trace the subpath through the SSR graph.
Why this matters
This is a spec-valid exports shape (subpath conditions are optional and "import" alone is legitimate for ESM-only subpaths). Any package can ship this and silently break on Vercel. PayPal's v6 SDK is one example; this will recur as more libraries publish ESM-only subpaths.
Environment
- Vercel Node.js runtime (Node 24)
@vercel/[email protected]preset- React Router v7 framework mode (Vite SSR)
@paypal/[email protected]
Happy to put together a tighter minimal repro repo if useful — let me know the shape you'd prefer (bare nft CLI invocation vs. full Vercel deploy).
I added a test here and it passes https://github.com/vercel/nft/pull/600 so there must be some information missing here
This behavior changed in v2.4 — the migration guide mentions it but it's easy to miss. Adding a note to the docs PR.
Still reproduces on 10.0.3 — the default condition does not fix it
Reopening with concrete evidence, since the invalid label rests on the assumption that adding a default/require condition to the subpath cures the mis-trace. It doesn't.
PayPal added the default condition in @paypal/[email protected] (paypal/paypal-js#979). On 10.0.3, the ./sdk-v6 exports now read:
// node_modules/@paypal/paypal-js/package.json → exports["./sdk-v6"]
{
"types": "./types/v6/index.d.ts",
"import": "./dist/v6/esm/paypal-js.js",
"default": "./dist/v6/esm/paypal-js.js" // ← added in 10.0.2
}
And that entry unambiguously exports the symbol:
// dist/v6/esm/paypal-js.js
export { loadCoreSdkScript, version }
Yet a static SSR import still mis-resolves to the v5 entry on a Vercel Node.js function and crashes on cold start:
import { loadCoreSdkScript } from "@paypal/paypal-js/sdk-v6";
^^^^^^^^^^^^^^^^^
SyntaxError: The requested module '@paypal/paypal-js/sdk-v6'
does not provide an export named 'loadCoreSdkScript'
So the presence of default is not the deciding factor — nft is picking the wrong entry regardless. Node's own ESM loader resolves the same specifier correctly at runtime; only nft's trace diverges.
Minimal shape to reproduce:
@paypal/[email protected](hasimport+defaulton./sdk-v6, exportsloadCoreSdkScript)- static
import { loadCoreSdkScript } from "@paypal/paypal-js/sdk-v6"in an SSR module traced by nft - deploy to a Vercel Node.js function →
SyntaxError ... does not provide an export named 'loadCoreSdkScript'on cold start
Current workaround (unchanged from the original report): swap the static import for a dynamic await import("@paypal/paypal-js/sdk-v6") gated to the client-only path, keeping it out of the SSR trace graph.
Given default is present and the mis-trace persists, this looks like an nft resolution bug rather than a package-config gap. Happy to provide a runnable repro repo if useful.