Auto import with TypeScript's preserveSymlinks flag

I'm currently trying to setup a monorepo for a TypeScript project using lerna.

Lerna will create symlinks for local dependencies inside each of the modules node_modules directory.

I've created a sample repository, so you just have to execute `npm install` in it in order to have the entire setup, for the sake of completeness, I'm gonna explain the general structure here anyways.

|- src/

|-- main/

|--- node_modules/

|---- @test/

|----- target/ -> symlink to src/target/

|--- index.ts

|--- tsconfig.json

|-- target/

 

src/main is a module with @test/target as it's only dependency, lerna symlinks this to the local version of it inside src/target.

When auto importing a function from src/target inside src/main/index.ts the file is resolved to '../target/index', presumably because the local dependency is a symlink to this location. The tsconfig.json has the preserveSymlinks flag enabled, so the symlink shouldn't actually get resolved.

 

If using the sample repository you can check how the typescript compiler is able to resolve the path with or without the preserveSymlink flag (`npm run expected` or `npm run actual` respectively).

 

Using the `paths` option of the Typescript compiler as used in this post with a fairly similar setup is an option (even though the incorrect approach imho) but resulted in a different issue, where '/index' is added to the path if both an index.ts and an index.d.ts file exist in the same directory (directory import is enabled).

 

Any feedback is appreciated!

Thank you

Leo

0
2 comments

Logged as https://youtrack.jetbrains.com/issue/WEB-30212, please follow it for updates.

I'd say that no support for monorepo projects is currently provided, so various issues can be expected when working with such setups

0
Avatar
Permanently deleted user

Hello Elena,

thanks for creating the issue.

I've added a comment to clarify the expected behavior in interaction with the preserveSymlinks flag, which you might want to include into the description (I have no idea how exactly you work with these tickets internally though).

0

Please sign in to leave a comment.