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

Warning or error when importing files from a project's own outDir #35082

Open
4 of 5 tasks
ablomen opened this issue Nov 13, 2019 · 3 comments
Open
4 of 5 tasks

Warning or error when importing files from a project's own outDir #35082

ablomen opened this issue Nov 13, 2019 · 3 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@ablomen
Copy link

ablomen commented Nov 13, 2019

Search Terms

import, outDir, composit, TS5055

Suggestion

Add a specific warning/error when trying to import something from the projects own outDir.

Use Cases

Help track down files that are wrongly importing from it's own dist directory.
I don't know if there are valid use cases where you would want to do this but I can only think of (refactor) errors.

Examples

In a big refactor I moved a class from a project to a shared directory (compiled with composite: true, imported into projects with "references").
I made the following change without thinking because it satisfied the compiler.

- import mongoose from "../../shared/dist/mongo";
+ import mongoose from "../dist/mongo";

Everything seemed to work fine (no error was shown in vscode on the import line itself, and the now shared class worked) until the next week I notice the following errors when compiling the shared dir:

error TS5055: Cannot write file '.../shared/dist/interfaces/branch.d.ts' because it would overwrite input file.
error TS5055: Cannot write ...

I did not notice these errors while doing the refactor itself because the tsc -w for the shared directory was running in a forgotten terminal tab. A warning or error on the import line itself when doing something like this would save a lot of debugging time.

Checklist

My suggestion meets these guidelines: (this is my guess, don't know exactly what the change would entail)

  • 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.
@RyanCavanaugh
Copy link
Member

I don't know if there are valid use cases where you would want to do this

If you have several different projects that write into the same common output directory, it's totally valid to do this.

@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Nov 13, 2019
@ablomen
Copy link
Author

ablomen commented Nov 14, 2019

Ok, might be more of a tslint thing then?

@ghost
Copy link

ghost commented Dec 2, 2021

+1 for a different error message at least. I just spent an hour on this confused why TS was trying to read anything from ./build as an input when I had rootDir, and includes only looking at ./src. Turns out I had one pesky import from 'this-package' statement.

Though I also don't understand why this is occurring at all. Why is TS trying to compile a .d.ts file outside of rootDir?

[edit] Nevermind, I get it. It's saying that it's already using a file in ./build as an input, not that it's explicitly trying to compile a file in ./build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants