-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Use absolute file paths in error messages #36221
Comments
I work with monorepos and vscode almost exclusively. I can never click to navigate to the errored file directly when working with TypeScript. This option would help productivity in my and similar use-cases. |
This would be a fantastic change for anyone working with monorepos. |
This is issue that exhibits for monorepos in IDEs, however also automatic recognition of file errors in GitHub Actions. Having the ability to switch to absolute paths... Either by default, through TSConfig, or through environment variable, would be great thing. |
Super Thumbs up! I have a large mono repo using yarn3 and if there is an error in src/index.ts, clicking on it in vsCode just gives me a list of all the src/index.ts files in all the packages or takes me to the src/index.ts if that exists in the root package. In a perfect world, tsc check the composite field in the tsconfig and if it is there, build a relative path back to the root (tsconfig without a composite field). |
Yep, came here for this. The default problem matcher instrumented by https://github.com/actions/setup-node does not know how to show proper annotations since the paths are relative. |
If anyone is looking for a hack to get things working in GitHub actions:
It just prepends $PWD to lines formatted like errors. |
It looks like this was actually the previous behavior of TSC at some point, interestingly enough: #7238 Agree that having this as an option would make using tsc with monorepos much easier. |
As far as I can tell, the main thing that would need to change is TypeScript/src/compiler/program.ts Line 659 in d8e81bb
and TypeScript/src/compiler/watch.ts Line 356 in d8e81bb
In order to support absolute path outputs in build and watch mode. |
FYI: Combining pipe-if-ci with reviewdog will work around the issue of GitHub Annotations not displaying. I think this will help you. |
I've got my own, similar, wrapper script to Given it has been almost 7 years since that issue was closed and JavaScript development practices & tooling have undergone a significant shift towards monorepo-style development patterns, I would love to see this decision revisited. |
Other ideas to solve the problem: How about outputting relative paths that are hyperlinked to absolute paths instead of absolute paths? That is, have tsc output logs like this $ printf '\e]8;;file:///Users/mizdra/src/github.com/mizdra/eslint-interactive/src/index.ts\e\src/index.ts\e]8;;\e\e]8;;\e\e\e]n' 2023-02-21.0.07.04.movMany modern terminals seem to support this feature. I think this approach would provide clickable paths without annoying the user with the length of the paths output. |
I have also though about this. At first this seems like the way to go (for any CLI tool that outputs file paths). However, TypeScript doesn’t just output file paths. It outputs |
The primary use-case for myself and several other users in this thread is having support for Github Actions' problemMatcher functionality, which uses a regex to extract error file paths, severity levels, and messages from CI runs and display them inline in Pull Request diffs. Extracted file paths must either be absolute, or relative to where the root of the repository is checked out within the CI environment. The link solution @mizdra suggested is an elegant solution for the local development, but most likely would not work in a portable or intuitive way with CI (for example, you'd probably have to write your own forked problemMatcher regex for filepath extraction rather than just being able to leverage the built-in functionality from Adding absolute path output in tsc error messages, combined with the work I've done in yarn@v3.4.0 to enable unprefixed output, would give |
Another possibility would be to add mono-repo to TypeScript itself. If it’s possible to type check multiple projects in one command, not only could TypeScript print relative paths properly, but it could share the document registry internally, which would enhance a performance. E.g.: tsc --project './packages/*' --project './examples/*' |
I've released a very simple drop-in replacement tsc wrapper, tsc-absolute, that fixes this problem. It's potentially preferable to other solutions (e.g. piping through awk/sed) as it generally keeps your npm scripts simpler, is portable across platforms, and ensures things like exit codes and signals are handled correctly. To install, it's as simple as:
This is really useful in monorepo setups for developer experience. It allows you to click to files in the terminal reliably, as well as match on filenames in CI. The README also includes a recommended GitHub problem matcher configuration, that I think catches the logs better (and supports the kinds of logs generated by monorepo tools like npm workspaces / yarn / nx / turborepo). |
Would a contribution for this change be accepted or are there considerations that have been not addressed? |
This isn’t really a problem when you use project references, which you should when dealing with mono repos. |
This isn't helping for our projects, for example. We are using Rush.js, the Microsoft's monorepo management tool, and each project within a monorepo has its own tsconfig. Then this issue becomes really visible. |
I've created a patch-package to display the full path:
|
Search Terms
absolute
Suggestion
Output absolute paths in type errors for
tsc
, or at least a way to specify this.Use Cases
When type checking in monorepositories, typically
tsc
is run for each workspace.tsc
is then run relative to the workspace it is run from, whereas developers are mostly interested in either the absolute path, or the path relative to the project root.I have configured my terminal emulator so I can CTRL-click a file and then the file is opened in VSCode, even on the correct line. This works for
tsc
output in simple TypeScript projects, because the file paths are relative to the project root. This also works for example for ESLint output, because it prints absolute paths. This does not work fortsc
in mono repositories, because the output ofyarn workspaces run tsc
is relative to that workspace.Examples
Clone and install a TypeScript mono repository.
git clone https://gitlab.com/remcohaszing/koas.git cd koas yarn
Let’s open the project using VSCode, since its builtin terminal is preconfigured to work with CTRL-click.
Run
yarn workspaces run tsc
in the VSCode terminal. This should work fine.Now mess up any type. I changed an instance of
koas.Middleware
tokoas.Middlewar
inpackages/koas-core/src/index.ts
.Run
yarn workspaces run tsc
in the VSCode terminal again. Now this outputs an error and a file path. The file path is not clickable, because it can’t be resolved.Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: