Skip to content

[api] Paths not resolved relative to tsconfigΒ #64842

Closed

Description

πŸ”Ž Search Terms

paths createProgram api relative

πŸ•— Version & Regression Information

  • This changed between versions 7.1.0-dev.20261002.1 and 7.1.0-dev.20261003.1

⏯ Playground Link

Playground Link

πŸ’» Code

import { API } from "typescript/unstable/sync"
import { createFileSystem } from "typescript/unstable/fs"
const projectDir = "/project";
const api = new API({ cwd: "/somewhere-else" });

// 1. Parse compiler options relative to the project directory.
const { options } = api.parseJsonConfigFileContent(
    {
        compilerOptions: {
            module: "esnext",
            moduleResolution: "bundler",
            noEmit: true,
            types: [],
            paths: { lib: ["./types/lib.d.ts"] },
        },
    },
    { configDirectory: projectDir },
);

// 2. Create a program with those parsed options.
const snapshot = api.createSnapshot({
    createPrograms: [{ rootFiles: [`${projectDir}/main.ts`], compilerOptions: options }],
    fileSystem: createFileSystem([
        [`${projectDir}/main.ts`, `import { x } from "lib";\nexport const y: number = x;\n`],
        [`${projectDir}/types/lib.d.ts`, `export declare const x: number;\n`],
    ]),
});
const diagnostics = snapshot.operation.createdPrograms[0].getSemanticDiagnostics([`${projectDir}/main.ts`]).flat();
api.close();

console.log(`  ${diagnostics.length ? diagnostics.map((d) => `error TS${d.code}: ${d.text}`).join("\n  ") : "OK: 'lib' resolved to /project/types/lib.d.ts"}`);

πŸ™ Actual behavior

The paths in tsconfig are resolved relative to the API cwd not the tsconfig.json path. This means we get error TS2307: Cannot find module 'lib' or its corresponding type declarations.

πŸ™‚ Expected behavior

paths are resolved relative to the tsconfig as before 7.1.0-dev.20261002.1.

As far as I can tell we can't change the cwd once we start the API so if we reuse the same API instance for multiple projects we can't just set cwd to the tsconfig path as we open a new projects.

Additional information about the issue

No response

Activity

  1. changed the title [-][api][/-] [+][api] Paths not resolved relative to tsconfig[/+] on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions