#4678·nitro

externals: absolute import of a traced package's `"."` export is rewritten to `pkg/` (ERR_PACKAGE_PATH_NOT_EXPORTED)

Author: gleknerCreated Sep 28, 2026Updated Sep 28, 2026

When a traced dependency is imported by the absolute path of its "." export, nitro:externals externalizes it as "dep/" instead of "dep", which fails at runtime.

Repro

node_modules/dep/package.json (conditional export; a plain ".": "./dist/index.mjs" gets bundled instead):

json
{ "name": "dep", "version": "1.0.0", "type": "module", "exports": { ".": { "import": "./dist/index.mjs" } } }

node_modules/dep/dist/index.mjs:

javascript
export const hello = () => "hello";

nitro.config.ts:

typescript
import { defineConfig } from "nitro";

export default defineConfig({
  compatibilityDate: "2026-09-01",
  preset: "node-server",
  traceDeps: ["dep"],
  handlers: [{ route: "/", handler: "./handler.ts" }],
});

handler.ts (use the real absolute path):

typescript
import { hello } from "/abs/path/to/app/node_modules/dep/dist/index.mjs";
export default () => hello();

npm i nitro rolldown && npx nitro build && node .output/server/index.mjs

Expected: .output/server/index.mjs imports from "dep". Actual: it imports from "dep/"; startup fails with ERR_PACKAGE_PATH_NOT_EXPORTED: Package subpath './' is not defined by "exports".

Versions: nitro 3.0.260903-beta and nitro-nightly 3.0.1-20260928-103646-f72e2ba6, Node 24.16.0.

Possible fix: flattenExports gives the "." entry subpath: "./", so guessSubpath returns join(name, "./") = dep/ (src/build/plugins/externals.ts:378). Returning name when e.subpath === "./" fixes the repro.