title: Nx Monorepo - How to Use NestJs Library inside the Main Nest App
body: <p>I am working in an Nx monorepo workspace. The workspace structure is something like below:</p>
  <p><a href="https://i.stack.imgur.com/zenPw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zenPw.png" alt="enter image description here" /></a></p>
  <p>The <code>api</code> is a NestJS app, and the <code>data-access-scripts-execute</code> is a NestJS lib.</p>
  <p>I don't know how I should import and use the mentioned lib controllers inside my api app. The following is my code:</p>
  <p><code>api</code>'s AppModule:</p>
  <pre><code>import { Module } from '@nestjs/common';
  import { ConfigModule, ConfigService } from '@nestjs/config';
  import { MongooseModule } from '@nestjs/mongoose';
  import { AppController } from './app.controller';
  import { AppService } from './app.service';
  
  // This line says 'Cannot find module '@something/data-access-scripts-execute'
  // or its corresponding type declarations.'
  import { SomeController } from '@something/data-access-scripts-execute';
  
  @Module({
    imports: [
      ConfigModule.forRoot({ isGlobal: true, expandVariables: true }),
      MongooseModule.forRootAsync({
        imports: [ConfigModule],
        inject: [ConfigService],
        useFactory: async (configService: ConfigService) =&gt; ({
          uri: 'mongodb://localhost/something',
          useFindAndModify: false,
        }),
      }),
    ],
    controllers: [AppController],
    providers: [AppService],
  })
  export class AppModule {}
  </code></pre>
  <p>lib's Controller:</p>
  <pre><code>import { Controller, Post } from '@nestjs/common';
  import { SomeService } from './some.service';
  import { SomeEntity } from './schemas/some.schema';
  
  @Controller('some-address')
  export class SomeController {
    constructor(private readonly _service: SomeService) {}
    
    @Post()
    async create(): Promise&lt;SomeEntity&gt; {
      console.log('create called');
      
      return this._service.create();
    }
  }
  </code></pre>
  <p>I should also mention that:</p>
  <ul>
  <li>All of my Angular libs can see other Angular libs</li>
  <li>My api app can see all of my Angular libs</li>
  <li>All of my NestJS libs cannot see other libs</li>
  <li>All of my NestJS libs cannot be seen by other libs and apps</li>
  </ul>
  <p>By the word <code>see</code> I actually mean <code>@something</code> which my project name.</p>
  <p>The following is also my <code>tsconfig.base.json</code> file which is located in the root of the workspace:</p>
  <pre><code>{
    &quot;compileOnSave&quot;: false,
    &quot;compilerOptions&quot;: {
      &quot;rootDir&quot;: &quot;.&quot;,
      &quot;sourceMap&quot;: true,
      &quot;declaration&quot;: false,
      &quot;moduleResolution&quot;: &quot;node&quot;,
      &quot;emitDecoratorMetadata&quot;: true,
      &quot;experimentalDecorators&quot;: true,
      &quot;importHelpers&quot;: true,
      &quot;target&quot;: &quot;es2015&quot;,
      &quot;module&quot;: &quot;esnext&quot;,
      &quot;lib&quot;: [&quot;es2017&quot;, &quot;dom&quot;],
      &quot;skipLibCheck&quot;: true,
      &quot;skipDefaultLibCheck&quot;: true,
      &quot;baseUrl&quot;: &quot;.&quot;,
      &quot;paths&quot;: {
        &quot;@something/system&quot;: [&quot;libs/system/src/index.ts&quot;],
        &quot;@something/feature-some-angular-lib&quot;: [
          &quot;libs/feature-some-angular-lib/src/index.ts&quot;
        ],
        &quot;@something/feature-some-angular-lib&quot;: [
          &quot;libs/feature-some-angular-lib/src/index.ts&quot;
        ],
        &quot;@something/shared&quot;: [&quot;libs/shared/src/index.ts&quot;],
        &quot;@something/data-access-scripts-execute&quot;: [&quot;libs/data-access-scripts-execute/src/index.ts&quot;]
      }
    },
    &quot;exclude&quot;: [&quot;node_modules&quot;, &quot;tmp&quot;]
  }
  </code></pre>
  <p>I should also say that the image is not complete becuase of privacy reasons.</p>