question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use absolute file paths in error messages

See original GitHub issue

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 for tsc in mono repositories, because the output of yarn 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 to koas.Middlewar in packages/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:

  • This wouldn’t be a breaking change in existing TypeScript/JavaScript code
  • This wouldn’t change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript’s Design Goals.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:27
  • Comments:6

github_iconTop GitHub Comments

1reaction
michal-kocarekcommented, May 2, 2022

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.

0reactions
austinpray-mixpanelcommented, Dec 7, 2022

If anyone is looking for a hack to get things working in GitHub actions:

eslint --pretty false | sed -E "s#^.+\(.+\): error TS.+\$#$PWD/\0#"

It just prepends $PWD to lines formatted like errors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Error: Detected an absolute file path. Paths starting with '/' are ...
This means that the reference is no longer dependent on the project's root file, but relative to the file where the reference is...
Read more >
What is the difference between a relative and absolute path?
In the example above, the absolute path contains the full path to the file and not only the file name as seen in...
Read more >
Can gcc be configured to not print out a full path in warning ...
Sometimes I use a sed script for that (f.e. when using cmake, which always uses full pathes). This can be useful also to...
Read more >
Relative and absolute paths, in the file system and on the web ...
realpath() command will convert a relative path to an absolute one. getcwd() will give you the current directory.
Read more >
File path formats on Windows systems | Microsoft Learn
As result, the first is an absolute path from the root directory of drive C: , whereas the second is a relative path...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found