Typescript auto-import local linked modules
Hi,
I've setup a project using lerna which links local folders as node_modules when necessary.
Let's say I have a this structure :
|- packages/
|-- a/
|-- b/
B is a typescript library with an barrel index at its root folder.
B is linked in A as a scoped module in the scope @test (so its local path is a/node_modules/@test/b).
Each time I'm trying to import a file in A, from B obviously, its auto imported path is relative to the file importing it (ex. ../../b/src/[...]), instead of putting the alias @test/b.
Any idea on how to achieve this result please :) ?
Edit : I've tried to use paths in the tsconfig.json without success so far.
Please sign in to leave a comment.
>B is linked in A as a scoped module in the scope @test
not sure I follow you. Is a file in your project dir a symlink to a file in node_modules? Or?
I'd say that Webstorm has multiple issues with soft links, due to its own limitations and limitations of Typescript service used for Typescript parsing, etc. see https://youtrack.jetbrains.com/issue/WEB-25420 and linked tickets
>>B is linked in A as a scoped module in the scope @test
>not sure I follow you. Is a file in your project dir a symlink to a file in node_modules? Or?
B is installed in the folder A node_modules, each package A and B are node projects to say so.
Would you prefer a github project as a sample ?
strange - to me, Webstorm never uses relative paths to import files from node_modules.
Yes, github project would be helpful
It apparently does if you specify a bad path in its tsconfig.json and / or if you specify an include rule.
I've managed to make it work here : https://github.com/nimaen/lerna-webstorm-import/blob/master/packages/test/index.ts
And here is the tsconfig content important part without any include rule :
```
"baseUrl": ".",
"paths": {
"@ab/core": [
"../core/*"
]
}
```
Tanks for the support :)
With your project, WebStorm does respect "paths": specified in tsconfig.json and generated imports as
Yes indeed.
It looks like however that Webstorm puts some relative paths if you use an "include" rule in the tsconfig.
Please can you provide a sample? What changes do I need to make to the provided project to recreate the issue?
Oh nervermind my last response, looks like it works with a correct include path like here :
https://github.com/nimaen/lerna-webstorm-import/blob/master/packages/test/tsconfig.json
Thanks Elena, I think you can close the ticket now.
Great, thank you!
Hi, sorry for Necroposting, anyways:
> I'd say that Webstorm has multiple issues with soft links, due to its own limitations and limitations of Typescript service used for Typescript parsing, etc. see https://youtrack.jetbrains.com/issue/WEB-25420 and linked tickets
It's 404 now, was that resolved? Because after `npm link` auto-import doesn't work for me, I have to unlink, npm install then invalidate cache and restart, which take forever.
@... @... Your links are down.
Indeed, this matter was resolved more than 3 years ago.