TypeScript Compilation Context Issue
The Issue
A file named acs.ts resides within the project in subfolder controllers. When the file is opened in Atom an error stating that the file is not included in the TypeScript compiler's context appears. When referencing tsconfig.json the "files":[] property contains the relative path to the acs.ts file and is saved to disk.
If the user clicks on the file reference link in the error, numerous (about 25 - 30) tabs open all referencing the file at a different location. The "different location" is inside of a Controllers folder within the same project. It is critical to note that the subfolder Controllers does not exist. Here are a few things that I have noticed while investigating the issue:
- When the file is opened as
Controllers/acs.tsthe compiler context error no longer appears. - A change made to the file in the fictional path
Controllers/acs.tswill appear in the file at the real pathcontrollers/acs.tsand the reverse holds true as well. - If the user were to completely quit Atom and then re-open the
controllers/acs.tsfile, the issue of opening numerous tabs will not occur. Instead it will behave as expected and bring the user's attention to the first line of the file. - Continuing to use Atom (opening, closing, and editing files) and then clicking the error will re-create the numerous tabs issue. Unfortunately a concise way to reproduce the bug has not been identified.
In an effort to identify a source for the bug, the subfolder controllers was renamed to Controllers and the compiler context error no longer appeared. Changing the folder name back to its lowercase representation again introduces the error. Note that the tsconfig.json file updated the "files":[] property to reflect the correct capitalization of the path.
A similar issue occurs with file tests/Credential/credentialHelper.ts. The major difference is that the error does not open a phantom file path, but instead opens the file at its real location. Again, the file's relative path is properly populated in the tsconfig.json file.
The project folder has been moved around the operating system as well as locations containing no spaces or special characters in the path. No location was found that resolved the compilation context issue.
System Information
OS: OS X El Capitan OS Version: 10.11 Atom-TypeScript Version: 7.5.0 Atom Version: 1.0.19 Node Version: 0.12.4 TSC Version: 1.5.0-beta
Unfortunately a concise way to reproduce the bug has not been identified.
I've had atom open 10s of tabs on error click as well. The api we use is fairly simple : https://github.com/TypeStrong/atom-typescript/blob/c0d11587e70b54272d7b5ad4497dd5fa35b88fe1/lib/main/atom/gotoHistory.ts#L17-L20
In the absence of repro I've failed to report it to atom/atom myself as well
Okay, well that helps to mitigate one bug that was discovered. Do you have any any ideas about why a file that is clearly included inside of the tsconfig.json "files":[] property would cause the compilation context error to appear?
Do you have any any ideas about why a file that is clearly included inside of the tsconfig.json "files":[] property would cause the compilation context error to appear?
nope :-/
@basarat I've been able to fix the multiple tabs opened when clicking on the error in the bottom panel (TS panel, not linter). Check the pull-request.
The problem was fairly simple - when you set the summary info in the TS panel you also adding a click listener to it by calling
if(handler) {
handler(this.summary);
}
But when you need to clear the error, it's just set innerHTML to empty string, but does not remove the onclick listener. Since the listener is added to summary element itself and not to it's content, we have event listeners added on each addError call and when we click on the error, we have tons of events that are calling gotoHistory.gotoLine and atom is opening tons of tabs (probably because all events are fired before any of tabs are opened).
There's a bigger issue behind this though. I figured that setErrors (in MainPanelView) is called from several places, even though the error itself is the same. It clears all previous errors (and now it does it right with removing the listeners as well), but still I guess we need to investigate on how to fix that.
I would add some check in the setErrors function if the error that you're trying to set is already there, but it might be a tricky case and I cannot come up with a good solution at this point.
igured that setErrors (in MainPanelView) is called from several places, even though the error itself is the same. It clears all previous errors (and now it does it right with removing the listeners as well), but still I guess we need to investigate on how to fix that.
A long term fix would be to move to something like react and use its diffing (dom reuse) and event delegation (single event handler) to not have to worry about trivial stuff like this. Checkout : https://github.com/TypeScriptBuilder/tsb/blob/7030bf44d1e3ff0d4d8ac56268120e6775cf3310/src/app/statusBar.tsx#L73-L103
Once that project is stable I'll start pushing code back here :rose:
I have the same issue in some components files of my project. Here my tsconfig.json:
{
"compilerOptions": {
"target": "ES5",
"module": "system",
"noImplicitAny": true,
"noEmitOnError": false,
"experimentalDecorators": true,
"removeComments": false,
"emitDecoratorMetadata": true,
"sourceMap": true,
"moduleResolution": "node"
},
"exclude": [
"bin",
"Properties",
"./node_modules"
]
}
some components files of my project
A path to a sample component file + screenshot please. I don't have a repro for out of context portion of this issue yet :rose:
I don't know if this is helpful, but I've experienced strange behavior when messing with the upper/lowercasing of files. As best I can guess, some important piece of the system seems not to be case sensitive. Given Typescript's origins, this doesn't surprise me a ton. The problem seemed to survive restarts of Atom, which leads me to believe that it had something to do with a mismatch between generated .js files and the .ts files.
but I've experienced strange behavior when messing with the upper/lowercasing of files
Very plausible. We use filePaths (made consistent with / some docs) all over the codebase as keys. Would only throw an error though if atom UI's view of the filePath is different from our background view of the filePath....
@basarat, I am sitting on a reproducible (on my machine) instance of the '"someFile.ts" is not included in the Typescript compilation context' problem. It's so reproducible on this one file that I can't get rid of it. :)
My whole project compiles just fine via F6, and the files array and filesGlob are both accurate, but the message persists. I don't have time to debug it right now, but at this rate it will be there when I do have time... looking like this weekend.
In the meantime, I can just report that, indeed, this file was once named with a capital SomeFile.ts. (Changing capitalization back and forth doesn't fix it, though)
Is there anywhere that atom-typescript caches information that would/could survive the act of quitting atom altogether?
Is there anywhere that atom-typescript caches information that would/could survive the act of quitting atom altogether?
Only if atom saves the file in its memory / storage as SomeFile.ts. Log out what you see in the developer console atom.workspace.getActiveTextEditor().getPath(); :rose:
If that is indeed the case, closing / opening the file should fix it maybe
atom.workspace.getActiveTextEditor().getPath();
returns the accurate, path to the file. Nothing I wouldn't expect.
Closing/opening the file has no effect. Renaming the file has no effect. Quitting/restarting atom has no effect. It just refuses to accept that the file is already in tsconfig.json's files array, even thorugh F6 works, the app works, etc.
I am running into the same issue with a project I've recently started introducing typescript into. In fact, it's the very first "mixed" project I've done. All of the other projects have been typescript from the very start and have had no issues.
In any case, one of the files that raises the error, ./src/components/Tag.tsx, does exist in the files array in the tsconfig.json file. If I remove it from the files list, it is picked up again by the filesGlob as expected. Now, if I copy the file to ./scr/components/Tag0.tsx there is no issue with that file. Both Tag.tsx and Tag0.tsx will be in the files array, and only Tag.tsx will display the error. If I remove the Tag.tsx file, the error goes away as expected. Now, this is where it gets really strange; If I create a new, empty, file with the name Tag.tsx, in the same place, it will display the error. On creation, the new file is added to the files as expected, but still same error.
I've restarted the app. I've nuked my .atom folder. Still, the issue remains.
Also, upon re-reading the other comments, the file mentioned above was copied into the project as tag.tsx and then renamed to Tag.tsx, as were some of the other files. The case in tsconfig matches the file, as does the getPath call.
Some more strangeness, if I create a new file ./src/components/tag.ts, the not in context issue for ./src/components/Tag.tsx disappears. As mentioned previously, the file was originally copied into the project as ./src/components/tag.tsx.
I can then delete the ./src/components/tag.ts file and the problem does not return until I restart Atom.
I have found my issue. I did some digging and tracked down the point at which atom-typescript's notion of my project files went wrong to here: https://github.com/TypeStrong/atom-typescript/blob/master/lib/main/tsconfig/tsconfig.ts#L461. Upon realizing what that code was for, I went through files carefully and found a couple import statements for the files in question that were not changed to the new casing. I would guess that the increaseProjectForReferenceAndImports is checking to see if the import exists, which on Windows and Mac it would (being case-insensitive), and then adds them to the runtime version of the project.
Reproducing is now easy:
- Create a new folder.
- Create file
one.tsas:
export class One {
}
- Create file
two.tsas:
import {One} from './one';
- Create
tsconfig.jsonusing atom-typescript command.
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"isolatedModules": false,
"jsx": "react",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"preserveConstEnums": true,
"suppressImplicitAnyIndexErrors": true
},
"filesGlob": [
"**/*.ts",
"**/*.tsx",
"!node_modules/**"
],
"files": [
"one.ts",
"two.ts"
]
}
- Rename
one.tstoOne.ts. - Notice that
tsconfig.jsonhas correctly updated toOne.ts.
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"isolatedModules": false,
"jsx": "react",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"preserveConstEnums": true,
"suppressImplicitAnyIndexErrors": true
},
"filesGlob": [
"**/*.ts",
"**/*.tsx",
"!node_modules/**"
],
"files": [
"One.ts",
"two.ts"
]
}
- Notice that
One.tsdisplays the not in context error.
It's great to have a such a simple reproduction documented -- thanks, @mmorton.
I'm able to reproduce it with that recipe on OSX (which is case-sensitive, as Unix cousin -- so on Mac and Linux, the One.ts will appear to be a different file from one.ts).
I don't understand what you mean by the rest of your report. You say:
Upon realizing what that code was for, I went through files carefully and found a couple import statements for the files in question that were not changed to the new casing.
What files did you go through where you found such import statements? When you say "for the files in question" which files are in question?
What's confusing to me is that, regardless of whether the file looks the same file or a different one, this problem has been seen to survive (or even return) upon reloads of the Atom UI, so as far as I know, we're looking for at least one place where information about the project is stored persistently (outside of the tsconfig.json file, which has been seen to have updated correctly to the new filename)..... I don't see any "extra" persistence of information happening in tsconfig.ts (yet).
I just did quit atom and then restart it.... One.ts is still listed as 'not in compilation context'... and when I save the file, one.js is created. So "somebody", somewhere is definitely writing down that the names of files outside of the project directory (and not keeping them up-to-date, presumably because it sees "one.ts" as equal to "One.ts". Why would saving the file names outside of tsconfig.json ever need to happen? Does ntypescript do such a thing? The answer may be the clue to where the issue lies.
Looking poked around a bit in ntypescript again just now, the DocumentRegistry interface jumps out at me, i.e. around
https://github.com/TypeStrong/ntypescript/blob/95f335ffa40201e8e459a0dc6b26f6dabfe88fc5/src/services/services.ts#L2018
export function createDocumentRegistry(useCaseSensitiveFileNames?: boolean, currentDirectory = ""): DocumentRegistry {
...
.... but that file has about a gazillion case-sensitivity workarounds in it, I guess for Windows' sake. One false move in here could result in what we're seeing, iff there is indeed a point at which it saves its impressions to disk other than the actual tsconfig.json (I haven't found such a place yet).
P.S. As I've said before is still true -- I'm not clear on where ntypescript stops and typescript begins... I'm just trying to peel back the onion here -- if I'm mischaracterizing what is ntypescript and what is tsc, please forgive me.
P.P.S. Obviously getting into debug mode would be a good thing. I might do that after another cup of coffee. Debugging child processes requires me to be on at least my second cup.
BTW, @basarat I'm not clear on how you were able to determine that this is fundamentally an atom issue. Can you explain? That might help with tracking this down.
One thing I noticed: I opened the test project which I created as per @mmorton in Atom Beta and the same problem is there... so if something has been written to disk, it might be somewhere that both instances of (Atom and Atom Beta) are seeing.
Also: the solution discussed here (remove from atom storage) doesn't solve it: https://discuss.atom.io/t/atom-is-loading-old-version-of-a-file-even-after-a-restart/17432/3 . In fact, moving the entire storage directory out of the way doesn't solve it.
I'm not clear on how you were able to determine that this is fundamentally an atom issue. Can you explain
@laurelnaiad based on the repro its not an atom issue. I was wrong :rose:
I'm not clear on where ntypescript stops and typescript begins
@laurelnaiad for all intent and purposes they are exactly the same. NTypeScript was started just as a nightly typescript release (before there was an official nightly), but it also does other little things (like a better definition file that exposes all the compiler private stuff ... which we need) which do not modify the main typescript code base in any way :rose: See the niceness list: https://github.com/TypeStrong/ntypescript#ntypescript
https://github.com/TypeStrong/atom-typescript/issues/681#issuecomment-168294607
@mmorton :100: thanks for the repro. I will look into that when I get time :rose:
Is there a solution for this issue ? Even Tho I added my files, one is not recognized .