-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
Strange "Cannot find module" error when using with TSLint and the no-unused-variable rule #74
Comments
Thank you for reporting this issue with reproduction repo :) I will check it, but I'm busy so it would be probably in the next week. But maybe someone else could help? PR's are welcome :) |
I stepped through the code and it looks like it happens for packages that specify A quick workaround is to do this: diff --git src/IncrementalChecker.ts src/IncrementalChecker.ts
index 56fdb70..ca69bda 100644
--- src/IncrementalChecker.ts
+++ src/IncrementalChecker.ts
@@ -115,6 +115,11 @@ class IncrementalChecker {
return files.getData(filePath).source;
};
+ // after linting, cached `SourceFile` instances may not be safely reused
+ files.keys().forEach(filePath => {
+ files.remove(filePath);
+ });
+
return ts.createProgram(
programConfig.fileNames,
programConfig.options, But obviously this has some perf impacts. I'm not sure how this can be properly fixed. |
Related tslint issue: palantir/tslint#2763 |
Thanks for the information @univerio - as I understand it this only occurs when the It's cool there's a workaround. Given this problem only occurs for the one rule I'm not that keen to use the workaround in all cases. I'm kinda reticent to use it at all given it's working around a problem in another package which might be fixed in future. That said, I'm wondering if it would be useful to put it behind a flag so you could "opt-in" to that behaviour. It could be driven directly from the What do you think @piotr-oles ? |
Thanks for looking into this and filing a bug with tslint, @univerio. Speaking for myself, due to this issue and the fact that lint rules which require type checking don’t show up in VSCode, I’m currently opting instead for |
@pelotom makes an excellent point; the various tsc |
@johnnyreilly It will not. palantir/tslint#1481 I actually dug around a little more last night, and it seems that the proper fix would be in tslint. The reason I say this is that I've noticed similar behavior in tslint-language-service. I have filed an issue with them with a (seemingly okay) patch. This fix works for tslint-language-service as well. |
As I commented on that issue, I don't want this rule to go away. I just want them to fix it! |
Is there any way a temporary fix could be applied in |
@clentfort You're right - I was just affected by this on a new create-react-app project using the new beta version of material-ui (https://material-ui-next.com/). It took me quite a while to troubleshoot it and find this thread. |
Oh, I'm so glad I finally found this—maybe a maintainer would like to add “Cannot find module” to the issue title, because I gave up on this plugin before coming back to it weeks later to discover this. |
@andrewbranch I changed the title |
so what is the actual fix for this? just ran into it, and am glad to have found the core issue at least. |
@kelly-tock my fix has been to abandon the |
@kelly-tock The actual problem exists in tslint itself, and, specifically, the way the In the meantime I've resorted to using a local fork of that rule with the patch in the linked issue. I've also come across the |
hmmmm...i'm still getting this issue actually.
I could not turn on noUnusedParameters at this time.
on tslint and after I run webpack, make an obvious change to cause lint error, I get
any thoughts? |
realized the project I was working with extended a few different configs, so I put |
I've noticed that this is only an issue when changing certain top-level files (at least in my current project). When changing most React components it doesn't occur. |
This is a very weird bug which took me hours to whittle down to a minimal example, so I hope it's of use. Steps to reproduce:
foo.ts
, add a newline or some other innocuous change, and save it.What the hey!?
Some observations:
index.ts
and saving it fixes the problem somehow.no-unused-variable
TSLint rule enabledmoment
is imported inindex.ts
, it may or may not exhibit the problem. For example,typestyle
exhibits the problem butrxjs
doesn't. I'm not sure what the commonality is among packages that run afoul of this.The text was updated successfully, but these errors were encountered: