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

Reconsider reading from multiple tsconfig.json files #402

Closed
rtsao opened this issue Sep 21, 2020 · 5 comments
Closed

Reconsider reading from multiple tsconfig.json files #402

rtsao opened this issue Sep 21, 2020 · 5 comments
Labels

Comments

@rtsao
Copy link
Contributor

rtsao commented Sep 21, 2020

Some packages such as react-dnd-touch-backend publish a tsconfig.json, which is causing esbuild to log a warning because the tsconfig references a JSON file that doesn't exist.

../app/node_modules/react-dnd-touch-backend/tsconfig.json:2:13: warning: Cannot find base config file "../../../tsconfig.base.json"
  "extends": "../../../tsconfig.base.json",
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning

The very latest version of react-dnd-touch-backend now prevents the tsconfig.json from being included in the published package, but this raises the question of why this is even being parsed and inspected by esbuild in the first place. It's worth noting that in my case, the TypeScript loader has not been enabled and no .ts source files are being referenced.

Is this a bug? I know tsconfig.json is also used for path aliases, but I figured esbuild would care about a tsconfig.json only in the root of the project. I'm not a TypeScript expert, but as far as I can tell, it doesn't look like nested tsconfigs are supported.

@evanw
Copy link
Owner

evanw commented Sep 21, 2020

I figured esbuild would care about a tsconfig.json only in the root of the project.

My rationale for supporting multiple tsconfig.json files is that you may want to use esbuild to bundle code across multiple TypeScript projects, each with its own tsconfig.json file. Doing this hasn't caused any issues so far other than the warnings as far as I know. I recognize that the TypeScript compiler doesn't work exactly like this. Potential solutions could be to remove this feature from esbuild (a breaking change) or to try to figure out a way to suppress these warnings. I'm also hoping that the plugin API can be extended to help address some of these things without needing to change esbuild's core (either multiple tsconfig.json files or custom per-file warning levels).

@rtsao
Copy link
Contributor Author

rtsao commented Sep 21, 2020

I see. For scenarios that involve bundling across multiple TS projects, how do you imagine that being structured in practice?

At least for the case of one TS project directly importing another, wouldn't any imports across project boundaries potentially break tsc? For example:

projects/
├── a/
│   ├── index.ts
│   │
│   │     import b from "../b/index";
│   │     console.log(b);
│   │
│   ├── index.js
│   └── tsconfig.json
└── b/
    ├── lib/components/foo.ts
    ├── index.ts
    │
    │     import foo from "components/foo";
    │     console.log(foo);
    │     export default foo;
    │
    └── tsconfig.json

          {"compilerOptions": "paths": {
            "components/*": ["lib/components/*"]
          }}

In this case, tsc in projects/a fails because components/foo cannot be resolved.

I'm wondering if there are bundling scenarios involving multiple tsconfigs that will never break tsc. The one I can think of is a non-TS project that imports two completely separate, independent TS projects. It makes sense to me that esbuild would support this limited scenario, but otherwise supporting multiple tsconfigs (especially in a nested manner) seems problematic, especially if it deviates from tsc.

@evanw
Copy link
Owner

evanw commented Sep 23, 2020

I have decided to suppress this warning inside node_modules directories. Leaving this open for the discussion about multiple tsconfig.json files.

@evanw evanw changed the title tsconfig-related warning from node_modules Reconsider reading from multiple tsconfig.json files Dec 12, 2020
@KatSick
Copy link

KatSick commented Aug 2, 2021

@evanw looks like, this warning is still present in bazel environments, since somehow

func IsInsideNodeModules(path string) bool {
does not find node_modules (probably because of bazel sym-links?)
Should I create separate issue?

@evanw
Copy link
Owner

evanw commented Apr 4, 2023

I'm closing this in favor of #3019, which is more comprehensive and which is a discussion that includes the TypeScript team itself.

@evanw evanw closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2023
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