You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
v10: false "Cannot find module" for an import of a file TypeScript only learns about later in the build (virtual modules) #1735
Found while working on #1734. It is on next (e241f23) without that PR, and #1734 does not change it.
Expected Behaviour
A module that exists only in webpack's input file system (for example one supplied by a virtual-modules plugin) can be imported from a TypeScript file without a type error, as long as webpack can build it.
Actual Behaviour
The importer gets a false error on the first build:
TS2307: Cannot find module './generated' or its corresponding type declarations.
webpack builds both modules and the bundle is fine; only the type check is wrong.
Why, from reading the code: app.ts is compiled before generated.ts. At that point TypeScript has never been told about generated.ts, because it isn't on disk and its contents only reach TypeScript when ts-loader compiles it. The end-of-build recheck then doesn't revisit app.ts: an import that failed to resolve isn't recorded as one of its dependencies, so generated.ts arriving doesn't make app.ts a dependant of anything that changed.
The same should apply to any file whose contents TypeScript can only get from ts-loader, not just virtual modules. I have only reproduced the virtual-module case.
No generated.ts on disk. A plugin makes webpack's inputFileSystem answer stat, readFile and so on for <context>/generated.ts with export const generated: number = 1;.
tsconfig.json with "files": ["app.ts"], ts-loader with type checking on (not transpileOnly).
Build once.
Result on next and on the #1734 branch: TS2307 on app.ts.
Location of a Minimal Repository that Demonstrates the Issue.
None yet. The plugin used to reproduce it is about 30 lines (a Proxy over compiler.inputFileSystem); it was written as a comparison test for #1734 and removed again, because it would have committed a snapshot of this false error.
Notes
A fix probably means recording unresolved imports per file, and rechecking those files at the end of a build in which new files became known to TypeScript.
Activity
refactor: split the handling of separate Vue blocks out of this pull …
fix: type check virtual modules, and builds after the TypeScript proc…
fix: keep a Vue file's script and template apart (#1743)