When dependencies are installed with pnpm, ts-loader behaves differently than tsc
Expected Behaviour
ts-loader should not report TS2305
Actual Behaviour
ts-loader report TS2305 error
Steps to Reproduce the Problem
- clone https://github.com/xbtsw/typescript-pnpm
npm i -g pnpmpnpm install- run
npm run tscand observe that the compilation success - run
npm startand observe error
This happens to both Linux and Windows 10 host.
Location of a Minimal Repository that Demonstrates the Issue.
https://github.com/xbtsw/typescript-pnpm
It looks like the type information is not visible to TypeScript when the dependency are symlinked and are compiled via ts-loader. I am willing to look into it but not sure where to start.
@iclanton FYI
Thanks for the detail! Wasn't there in one of the recent TypeScript releases about symlinks? I forget the details...
@johnnyreilly Indeed, I read @zkochan mentioned that TypeScript resolved some issues on their end in order to get it working with pnpm, maybe he has more insight into those issues.
It will be great if we can get ts-loader working too, as almost all front-end projects using TypeScript will go thru webpack and ts-loader.
If I remember it correctly, the issue with TypeScript was that it was preserving symlinks when resolving typings in node_modules. This issue was present in typescript@1
The main idea is simply calling fs.realpathSync() in the right places, to be consistent with how NodeJS resolves modules. This was solved a long time ago in typescript@2 by adding realpathSync to their OS abstraction and plumbing it through all the needed places.
Thanks for the insight @zkochan and @pgonzal. The reasoning I have so far is that since tsc works while ts-loader doesn't. It should be the case that they setup the TypeScript compiler differently, the problem shouldn't be with the compiler itself, otherwise tsc would fail too.
I compared the compiler setup code in ts-loader and tsc but wasn't be able to get very far there.
I'm guessing the change would just be switching readFile implementation in https://github.com/TypeStrong/ts-loader/blob/master/src/utils.ts to use fs.realpathSync() in some way? Why don't you fork and experiment?
Feel free to submit a WIP PR if you get somewhere. I'm totally happy to help with tests etc
These info are very insightful. I am taking a look into it now. Thanks guys.
Thanks for your work! Released with https://github.com/TypeStrong/ts-loader/releases/tag/v4.3.0