ITADN

packageId is not set when calling resolveModuleName on a directory with an index.d.ts file in a dependency

#63547ClosedTheLazySquid 创建于 2026-06-10
Won't Fix
T
TheLazySquidcommented
### 🔎 Search Terms packageId, resolveModuleName, index.d.ts ### 🕗 Version & Regression Information - This is the behavior in every version I tried, and I reviewed the FAQ for entries about this issue ### ⏯ Playground Link https://github.com/user-attachments/files/28815038/repro.zip ### 💻 Code ```js import ts from "typescript"; import { resolve } from "path"; const importer = resolve("node_modules/@dimforge/rapier2d-compat/pipeline/world.d.ts"); const resolved1 = ts.resolveModuleName("../control", importer, {}, ts.sys); const resolved2 = ts.resolveModuleName("../control/index", importer, {}, ts.sys); console.log(resolved1.resolvedModule.packageId); // undefined console.log(resolved2.resolvedModule.packageId); // defined properly console.log(resolved1.resolvedModule.resolvedFileName === resolved2.resolvedModule.resolvedFileName); // true ``` ### 🙁 Actual behavior If a dependency contains a directory with a file called `index.d.ts`, say `dir/index.d.ts`, resolving the file with `typescript.resolveModuleName` only sets `resolvedModule.packageId` when resolving `dir/index`, and not when resolving `dir`. In both cases `resolvedModule.resolvedFileName` is the same. I tested this with moduleResolution: "bundler" and ran into the same issue. ### 🙂 Expected behavior `packageId` should be set regardless of if the index file was resolved indirectly ### Additional information about the issue I noticed this issue with [@dimforge/rapier2d-compat](https://www.npmjs.com/package/@dimforge/rapier2d-compat), but I imagine it happens elsewhere. This is an issue for me because `rollup-plugin-dts` doesn't know that it should inline the types because it doesn't know the name of the module they are from.
关闭于 2026-06-16 3 条评论