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

Error messages use relative paths instead of absolute #7238

Closed
hesselink opened this issue Feb 25, 2016 · 11 comments
Closed

Error messages use relative paths instead of absolute #7238

hesselink opened this issue Feb 25, 2016 · 11 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Revisit An issue worth coming back to Suggestion An idea for TypeScript

Comments

@hesselink
Copy link

TypeScript Version:

1.8.2

Problem

I've found that somewhere between typescript 1.6.2 and 1.8.2, it started printing relative file names in error messages instead of absolute file names. This makes it harder for us to find the right (generated) input file, since we have to know what the paths are relative to. Was this change on purpose, or accidental? It's not listed in the change log.

@mhegazy
Copy link
Contributor

mhegazy commented Feb 25, 2016

it is intentional. they are relative to the current directory the compiler was executed in. this make it much easier for command line scenarios when you run tsc in a folder, instead of all errors having full folder path, it becomes much more user friendly.
How are you running tsc? VS? command line?

@hesselink
Copy link
Author

We are running tsc from a custom build tool, which runs as a server watching the source directory for changes. So I guess for us it will be relative to whatever the working directory is for the build server, which is launched by another tool and runs in the background. The paths end up looking like ../../../build/some/generated/path/file.ts, which makes it hard to open them since you're not in the working directory and probably don't know what it is.

But I can see that this scenario isn't common, and that the relative paths are friendlier when used directly from the command line on non-generated source files.

@mikeyoon
Copy link

I noticed another side-effect of this change is that Webstorm will not link the file in the terminal since it expects absolute paths for its output filter macro.

@aychtang
Copy link

+1

It would be nice to have a compiler option to print absolute file paths of input files with errors for backwards compatibility.

This would involve adding a new compiler option and a dependant code branch in getCommonSourceDirectory() from src/compiler/program.ts.

@mhegazy mhegazy added Suggestion An idea for TypeScript Declined The issue was declined as something which matches the TypeScript vision labels Mar 28, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Mar 28, 2016

New compiler options add complexity both for usage and for maintenance. i would punt on this issue for now unless there are new scenarios.

@mhegazy mhegazy closed this as completed Mar 28, 2016
@hesselink
Copy link
Author

That's too bad, since it means we'll have to:

  • Carry state about the current working dir of typescript in our tooling.
  • Parse the type script output.
  • Rewrite the output to have absolute paths.

This will be a lot of finicky work that typescript could do much more easily. I do see the point about adding complexity in the compiler, just be aware that this shifts the complexity to some of your users.

@mhegazy mhegazy added the Revisit An issue worth coming back to label Mar 29, 2016
@mredbishop
Copy link

This is also the same problem when running a tsc build task from VS Code. It's similar to webstorm in that the relative paths do not become links whereas previously, full-paths did. I agree with @aychtang that this should be a compiler option for backwards compatibility for the large number of people who've built their tool chains around the previous functionality.

@wgv-sethlivingston
Copy link

I also get the point about compiler complexity, but this forces us to jump through hoops to do something that we've been able to do for years and years: double click on an error to jump to the source line.

@ulrichb
Copy link

ulrichb commented Sep 10, 2016

Please revisit this and add a "emit full paths" compiler option.

My situation: In a VS project I call gulp (with gulp-typescript) in a post-build action. The problem is that tsc emits the path in the error messages relative to the gulpfile, but VS expects them to be relative to the project dir. => I cannot double-click the error messages, unless I apply the following workaround in my gulpfile.

gulp.task("build",
    withChangedWorkingDir("dir/to/my/project", function () {
        var tsProject = ts.createProject("tsconfig.json");

        var tsResult = tsProject.src().pipe(ts(tsProject));

        return tsResult.js.pipe(gulp.dest("."));
    }));

function withChangedWorkingDir(path, callback) {
    return function () {
        var savedDir = process.cwd(path);
        process.chdir(path);
        try {
            callback();
        } finally {
            process.chdir(savedDir);
        }
    };
}

EDIT: The above workaround doesn't work when using a files-array in the tsconfig.json (tsc searches in the wrong directory). Instead, I configured a custom "reporter" for gulp-typescript.

@RyanCavanaugh
Copy link
Member

I think you'd have to change gulp-typescript in that case -- it has access to the error message objects and only it can know what the "correct" relative filenames are

@ulrichb
Copy link

ulrichb commented Sep 13, 2016

only it can know what the "correct" relative filenames are

I need full file paths (enabled by a compiler option) in all error messages, like it happens for paths outside of the rootDir (referenced by ///<reference...), resp. like it happened for all messages before 1.8 (see 884dff0),

Regarding change in gulp-typescript: yes, possible + in all the other tsc-wrappers where I need VS-compatible output, instead of a central option in tsconfig.json :/

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Revisit An issue worth coming back to Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

8 participants