1

I am trying to migrate to Nx and setup a monorepo. Currently running into issues with path alias imports.

@backend/kernel": ["libs/kernel/src/index.ts"],
@backend/kernel/*": ["libs/kernel/src/*"]

When issuing imports of the form import { Something } from "@backend/kernel".

On the other hand, when doing imports that go deeper, import { SomethingElse } from "@backend/kernel/somewhere/deeper" I get TS2307 when compiling. No issues in VSCode; all types are correctly resolved.

Anybody has some advice?

muffe
  • 47
  • 7

1 Answers1

0

Have you export the code correctly from your lib in the root index of your library ? If not, at the index.ts at the root of your library, just export your code like this :

export { Something } from 'your/path'

or if you already export inside your library you can use a wildcard *.

After that, remove the line @backend/kernel/": ["libs/kernel/src/"] from your tsconfig.base.json Cheers

Chalom.E
  • 617
  • 5
  • 20
  • How do you mean? I am exporting from `index.ts`, but I would also like to have the possibility of importing from directories within the library, hence the wildcard path. VSCode seems to be quite happy with this configuration, but it is during compilation issues arise. – muffe Jul 15 '22 at 09:03
  • This is because VsCode rely on language service and let you import like this, but the build will always failed. This is the same for dependencies import from node_modules with VsCode. It is not the case for webstorm for example that does not rely on language service. I suggest to export at the root of your library. The libraries in nx are inherited by the whole project. – Chalom.E Jul 15 '22 at 12:32