Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsconfig loading issue with monorepo #1851

Open
tomwidmer opened this issue Jan 15, 2024 · 2 comments
Open

tsconfig loading issue with monorepo #1851

tomwidmer opened this issue Jan 15, 2024 · 2 comments
Labels

Comments

@tomwidmer
Copy link

tomwidmer commented Jan 15, 2024

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.

@jonaskello
Copy link

Maybe using the get-tsconfig package to load the tsconfig.json would help.

@arthurfiorette
Copy link
Collaborator

I fixed these tsconfig problems in kitajs with this function:

https://github.com/kitajs/kitajs/blob/caf72f23359bbfc2829cc6e8c8083881a311fc78/packages/common/src/config/tsconfig.ts

maybe it also solves this issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants