VSCode import ignoring symlinks in favour of deeper node_modules

Viewed 359

I’m having issues with VSCode/TS and auto imports.

We have a service, let’s call it Manager. Manager imports some functions from a private npm package called Helpers. Both Manager and Helpers import types from another private package called Types.

When working locally I add to Types and then npm link types in Manager to access the new types without having to publish the Types package (have done this on previous codebases with no issues, worked wonderfully)

Enter the problem … once symlinked the statement for import { newType } from '@companyName/Types' actually resolves to node_modules/@companyName/Helpers/node_modules/Types and no amount of me saying otherwise will dissuade it from that.

I assumed this was a VSCode issue, however if I restart the Typescript server there is a brief window where it defaults to the correct package path and VSCode can see the type. After a few seconds (I assume once TS server comes back up) it shows an error and we are back to importing from the wrong place.

I can fix this with a relative import to the node_modules but this feel less than ideal.

Does anyone have a clue what could be going wrong here? It’s like TS doesn’t want to use a symlinked import if it can find it somewhere not symlinked

1 Answers

Found a solution, adding this to the tsconfig sorted it:

"paths": {
      "@companyName/types": [
          "../node_modules/@companyName/types"
      ]
    },
Related