Skip to content

tsconfig loading issue with monorepo #1851

@tomwidmer

Description

@tomwidmer

When trying to use this tool in a monorepo, I'm getting 'module not found' errors for some of my cross-module imports that rely on the paths setting in tsconfig. This seems to be due to an issue with how the tsconfig file is being loaded when your tsconfig is in a subdirectory and extends other tsconfig files:

i.e. tsconfig: 'lib/mydomain/tsconfig.lib.json':

{
  "extends": "./tsconfig.json",
  // ...
}

In loadTsConfigFile.ts, you have:

const parseResult = ts.parseJsonConfigFileContent(
    config.config,
    ts.sys,
    path.resolve(path.dirname(configFile)),
    {},
    configFile
);

If I log parseResult, I see it has errors and is unable to find./tsconfig.json, since it's resolving configFile against the passed basePath path.resolve(path.dirname(configFile)), which is yielding a path of lib/mydomain/lib/mydomain/tsconfig.lib.json. The trivial fix is to pass path.resolve(configFile) as the 5th argument, instead of configFile. Making this change locally resolved the issue.

See https://github.com/microsoft/TypeScript/blob/cf33fd0cde22905effce371bb02484a9f2009023/src/compiler/commandLineParser.ts#L2074 for the equivalent code in tsc, which does indeed resolve the path of configFile.

I couldn't find a workaround, since your code handles the tsconfig loading and there's no way to specify the config manually.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions