Skip to content

resolveDtsSync unable to handle magic-string #1046

Description

@ocavue

Run the following code:

import { ResolverFactory } from "oxc-resolver";

const resolver = new ResolverFactory({
  mainFields: ["types", "typings", "module", "main"],
  conditionNames: ["types", "typings", "import", "require"],
  extensions: [
    ".d.ts",
    ".d.mts",
    ".d.cts",
    ".ts",
    ".mts",
    ".cts",
    ".tsx",
    ".js",
    ".mjs",
    ".cjs",
    ".jsx",
  ],
});

const currentFile = import.meta.filename;
console.log("Current file:", currentFile);

for (const pkg of ["magic-string"]) {
  const resolved = resolver.resolveDtsSync(currentFile, pkg);
  console.log(`Resolved ${pkg} to`, resolved.path);
}

Output:

Resolved magic-string to /..../node_modules/magic-string/dist/magic-string.es.mjs

It should resolve to dist/magic-string.cjs.d.ts as magic-string/package.json's types field.

Full reproduction: https://github.com/issueset/oxc-resolver-dts-issue.git

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions