Webstorm imports modules linked with npm link by local path instead of module name

This is the same issue as https://youtrack.jetbrains.com/issue/WEB-51752, but the author abandoned it and it's still valid for me on Webstorm 2022.2.3 more than a year after the previous issue, so raising a new one.

Let's say I have a library within my organization called @some-org/some-lib, and usually auto-import will import that lib fine as import Foo from '@someorg/some-lib', but while working with npm link to make changes to my lib while using those changes from my application, it will add imports such as import Foo from ../some-lib/src/foo (which is where my library is located on my local machine during development).

This means that when I'm done with my local changes to the library used by my app and publish my library, I then need to manually perform a regexp search & replace to get rid of all faulty imports. This is something you're bound to forget and it turns out only in CI as a build error. :/

It also have other side-effects during development, such as tsconfig options in the application being enforced onto code in the library. In my case I had a dynamic import in the library together with "module": "commonjs", and when this code was imported by local path from my application the build failed with TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'. This had me quite stumped (but actually caused me to realize about the invalid imports being there).

Expected behaviour: keep track of original module names for modules linked with npm link instead of resolving to local paths.

Please sign in to leave a comment.