-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
The compilerOptions.outDir
config is incorrectly resolved when in a shareable config
#29172
Comments
Path-based compiler options ( It would be horribly breaking to change this behavior now~ |
But this makes "extends" pretty useless. Without outDir you cannot use project references with extends. A The use case for extends is that I specify baseline options for the compiler but paths and references should be based on project settings. It should be possible overwrite paths or even individual options. @myscope/tsc-config/tsconfig.base.json {
"compilerOptions": {
"moduleResolution": "node",
"target": "ES2018",
"newLine": "lf",
"jsx": "react",
"strict": true,
"allowSyntheticDefaultImports": false
} @myscope/my-project/tsconfig.json {
"extends": "@myscope/tsc-config/tsconfig.base.json",
"compilerOptions": {
"moduleResolution": "node",
"target": "ES2018",
"newLine": "lf",
"jsx": "react",
"outDir": "lib",
"strict": true,
"allowSyntheticDefaultImports": true
} Resolved config: {
"compilerOptions": {
"moduleResolution": "node",
"target": "ES2018",
"newLine": "lf",
"jsx": "react",
"outDir": "@myscope/my-project/lib",
"strict": true,
"allowSyntheticDefaultImports": true
} This should be a non-breaking change. |
Just want to chime in, I'm really surprised these paths are resolving relatively. This really makes config extensions much less useful. I really just want to set my Took me a hot minute to find my build files inside |
You're correct that this is a breaking change though. Everyone is setting their paths in shared configs with |
I think this is very confusing, I read the docs about extends and when I read:
I took this at it's word that if I used a relative path such as
in the base configuration path would be resolved relative to the base configuration's path. The implication here is that non-relative paths are not relative to where they appear but rather the project wherever
to be relevant to the project. It seems however that |
Since changing this behavior would be a breaking change and is impossible to make backwards compatible, could we maybe create new keys that resolve relatively? I vote I'm opposed to the idea of making them something explicit like |
The current implementation is rather unfortunate as it results in surprising behaviour. In addition to Incidentally, in the MSBuild config inheritance implementation (Directory.build.props), the setting for There is a proposal for a non-breaking implementation in #30163 |
I agree, got confused about it as well. Any plans to change this behaviour to support relative paths in shareable configs? |
Rather than a breaking fix, couldn't one just handle placeholder variables, such as $PROJECT_DIR or $ROOT_DIR? So the |
It's such a surprise that Consistency? YES definitely. As a workaround, here is my hack:
$ ln -s node_modules/<tsconfig_config_pkg>/tsconfig.json tsconfig.base.json
{ "extends": "./tsconfig.base.json"} Would be great if suggestion such as #30163 can be accepted!!! |
I ran into this while making pnpm use a shared config. |
BREAKING CHANGE: Removed the following properties: - `compilerOptions.rootDir` - `compilerOptions.outDir` - `include` The reason for this removal is the following issue: microsoft/TypeScript#29172 closes #53
@weswigham what's about this comment from @MartinDoyleUK ? Would love to see this solution. |
Not sure if related or different bug / feature, but I have (v 3.6.3):
If I use the path in imports:
generated files will look like:
without the import using the path config (but keeping the path config)
Full tsconfig
build command
|
Just define |
@weswigham any news on this? I found @MartinDoyleUK's idea to intro |
Would it be possible to describe this behavior explicitly on https://www.typescriptlang.org/tsconfig#outDir ? |
Just stumbled on this as well. This is so weird, the one thing I was sure extending another configuration would enable was using a single configuration for all the settings shared between projects. Like it's annoying to say to TS for every project to get the files from "src" and to put them in "dist". |
I would love to see this closed/fixed so it just works. After trying quite a few monorepo setups in typescript(I come from java-land where it was a much easier task), this monorepo setup below seemed the best but you run into this github issue. |
- base, library, and library-build, same as the package exports - initially started with library, but if I wanted to use this repo for apps as well, I wouldn't want some configurations like declarations or declaration maps as they're unused by apps - so split off library and base - library-build doesn't add much and is for a particular use-case, so I also may end up removing that at some point - NOTE: `extends` resolves relative paths based on the location of the _extended_ config file, not the one doing the extension - https://www.typescriptlang.org/tsconfig#extends - This effectively means that all "path-based compiler options" like `outDir`, `outFile`, `rootDir`, `include`, `exclude`, and `files` have to be repeated in all tsconfigs - c.f. microsoft/TypeScript#29172, microsoft/TypeScript#25430 - so the usage of them here is more of as an "example" of sorts of what should be repeated, as installing from NPM would result in the paths here being _inside_ `node_modules` (or elsewhere pending the NPM client you use)
Basically same as agilgur5/react-signature-canvas@cc6cce9 - this is my own tsconfig base (https://github.com/agilgur5/tsconfig) built on top of @tsconfig/strictest (https://github.com/tsconfig/bases) - as you can see, it just reduces all the non-type-checking related config that @tsconfig/strictest doesn't cover - TS doesn't yet support package `exports` for tsconfigs yet (microsoft/TypeScript#48665), hence the longer path into the package - Relative paths in tsconfig bases are also relative _within_ `node_modules` (microsoft/TypeScript#29172), so have to repeat any relative paths here - And due to this, I think it's better right now for `build` to extend the base here instead of the `build` tsconfig in `@agilgur5/tsconfig` - I didn't fully think that one through when I made it tbh, though it still serves as a good example tsconfig - Maybe that will be different in the future if TS changes or otherwise comes up with a solution to this (see the issue)
As per @MartinDoyleUK 's suggestion - which is similar to what Jest has done with |
Paths in tsconfig are relative to the config fine in which they are declared. So any path declared in `packages/tsconfig/base.json` is relative to that directory. This applies in particular to `outDir` and `include`. These have to be redeclared in each `tsconfig.json` file in each library. See microsoft/TypeScript#29172
4 years and we still can't get one of the non-breaking solutions merged? |
I just was making a new project in TS (pretty much the first time I'm doing a monorepo TS project from the scratch) and I also faced this issue. I was expecting paths to be resolved from the "final" None of workarounds menitoned during the discussion works. I also have a feeling that adding root directory variable would be a viable solution to this - though discovery of it wouldn't be perfect. The only solution for me is to use: {
"extends": "../tsconfig-package.json",
"compilerOptions": {
"outDir": "./dist", // Needed due to https://github.com/microsoft/TypeScript/issues/29172.
}
} Which is not ideal but still makes few lines to be reused. |
My workaround works and I use it daily. You need to install a dependency that exports a It's weird, but that works, unless you are using a package manger that isn't really installing things but just symlinking them or something. |
I faced this issue. Assuming I have a monorepo.
Every {
"extends": "../../tsconfig",
"include": ["src"],
"exclude": ["**/*.spec.ts"],
"compilerOptions": {
"outDir": "dist"
}
} It's redundant and ugly. |
This is honestly crazy. about five years later and we still don't have anything. even just an extra config property we could put in the base/shared config like |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
We're discussing options about this at #56436 |
Wow, great to know a solution has been implemented and merged! As far as I understand it, soon we should be able to write a base config such as: // @fileName: tsconfig.base.json
{
"compilerOptions": {
"rootDir": "${configDir}/src",
"outDir": "${configDir}/lib",
"tsBuildInfoFile": "${configDir}/lib/.tsbuildinfo",
}
} |
until microsoft/TypeScript#29172 makes its way into a release at least
TypeScript Version: 3.3.0-dev.20181222
Search Terms:
outDir
,output directory
,outDir extends
Expected behavior:
TypeScript 3.2 got support for configuration inheritance via node_modules packages. I have created a package with a shareable config. In this shareable config, I have defined the
outDir
option: https://github.com/sindresorhus/tsconfig/blob/50b0ba611480ed45b97a59b910f5bb5e8cbc25ef/tsconfig.json#L2-L3 as I always use the sameoutDir
and don't want to have to specify it in each project.I expected the
outDir
path to be resolved against the project root, even when it's defined in an extended config.Actual behavior:
It turns out the
outDir
relative path is actually resolved against the shareable config path instead of the project's root (tsconfig.json
) path. So when I have a projectfoo
, and compile TypeScript, the output ends up infoo/@sindresorhus/tsconfig/dist
instead offoo/dist
.You can reproduce it by cloning https://github.com/sindresorhus/ow/tree/8ae048c4931dfd51b496cefb40b24c78d3722be6, then removing this line https://github.com/sindresorhus/ow/blob/8ae048c4931dfd51b496cefb40b24c78d3722be6/tsconfig.json#L4 (which is a workaround to the problem), and then run
$ npm test
. The compiled TS code will end up innode_modules/@sindresorhus/tsconfig/dist
instead ofdist
.The text was updated successfully, but these errors were encountered: