Убедитесь, что вы проверяете диагностику в программе. Я могу получить диагноз c, который вы описываете, проверив ts.getPreEmitDiagnostics(program)
.
Код воспроизведения
Вот некоторый код воспроизведения с использованием @ts-morph/bootstrap
:
import { createProjectSync, ts, InMemoryFileSystemHost } from "@ts-morph/bootstrap";
// file system setup
const fileSystem = new InMemoryFileSystemHost();
fileSystem.writeFileSync("/tsconfig.json", `{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
}
}`);
fileSystem.writeFileSync("/src/file.ts", `import "../otherDir/file";`);
fileSystem.writeFileSync("/otherDir/file.ts", `export class Test {}`);
// create project and program
const project = createProjectSync({
tsConfigFilePath: "./tsconfig.json",
fileSystem,
});
const program = project.createProgram();
// output diagnostics
const diagnostics = ts.getPreEmitDiagnostics(program);
console.log(project.formatDiagnosticsWithColorAndContext(diagnostics));
Выходы:
src/file.ts:1:8 - error TS6059: File '/otherDir/file.ts' is not under 'rootDir' '/src'.
'rootDir' is expected to contain all source files.
1 import "../otherDir/file";
~~~~~~~~~~~~~~~~~~