Typescript: When monorepo like packages are linked through symlink and are not built editor cant resolve modules

Created on 25 Oct 2019  路  4Comments  路  Source: microsoft/TypeScript

@sheetalkamat - I am trying this out and noticed that it doesn't work in the case of things that are imported from the outDir rather than the src (in the case of a monorepo):

image

For a quick way to verify this, I prepared a monorepo for you to check it out:

https://github.com/kenotron/TypeScriptMonoRepo/tree/ts3.7

Things work okay if you do "yarn && yarn build", but if I understand this feature, it is meant to address the case where you can start editing in VS Code with Intellisense even before having to build something because we're traversing source rather than output.

_Originally posted by @kenotron in https://github.com/microsoft/TypeScript/pull/32028#issuecomment-545637314_

Fix Available

Most helpful comment

~@sarpik - the only workaround I see currently is to use the main field to point to a single entry point index. I currently have to create a script to change this at pre-publish time~

Update: nevermind, @sheetalkamat actually has a good fix for this and I've verified that this WORKS

All 4 comments

Have investigated this and currently we are not handling symlinks.. If the resolution happens to be looking at the output path for the referenced project, we make sure that the answer to fileExists and directory Exits is true so that the resolution uses the output file even when its not present.
In case of symlinks those paths are different eg. its looking for outDir in "c:/temp/TypeScriptMonoRepo/node_modules/b/lib" instead of "c:/temp/TypeScriptMonoRepo/packages/b/lib". If resolution had asked for the later we would answer yes and resolution will succeed and we will use source file instead.

How hard is it to provide a flag here to traverse symlinks? I think this would enable a lot of monorepos to use this feature directly without resorting to the hack of the main field being src/index.ts

This applies to yarn workspaces (since symlinks are used under the cover) and it would be extremely useful to have them supported. Currently we still have to build manually..

~@sarpik - the only workaround I see currently is to use the main field to point to a single entry point index. I currently have to create a script to change this at pre-publish time~

Update: nevermind, @sheetalkamat actually has a good fix for this and I've verified that this WORKS

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Antony-Jones picture Antony-Jones  路  3Comments

Roam-Cooper picture Roam-Cooper  路  3Comments

manekinekko picture manekinekko  路  3Comments

remojansen picture remojansen  路  3Comments

jbondc picture jbondc  路  3Comments