I have Microservice with Nestjs and Nx
this is project structure
project
│
│
└───apps
│ │ gateway
│ │ auth
│
│
└───libs
└───common
now I want to import some module from libs/common
in gateway
import { RMQ_SERVICES } from '@app/common/constants/rmq.constant';
but it doesn't work
Cannot find module '@app/common/constants/rmq.constant' or its corresponding type declarations.ts(2307)
I have also tried this
import { RMQ_SERVICES } from 'libs/common/src/lib/constants/rmq.constant';
but it doesn't worked .
Projects cannot be imported by a relative or absolute path, and must begin with a npm scopeeslint
so how can I do it ?
If these were created with the nx generators then your tsconfig.base.json
should contain the proper paths
for mapping the libraries. Generally your nx.json
will have an npmScope
property that is your @scope/
and then depending on how you set up the --importPath
option that should define what path you need to use. Check your base tsconfig.base.json
to see what the path is otherwise. I usually have libraries like @scope/server/kysely
or @scope/shared/types
in my Nx monorepos, like this one here.
If these were not created with the Nx generators, then you'll need to add the path mapping to your tsconfig.base.json
yourself and make sure that the tsconfig.json
of your applications are updated to extend from the base config