question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reuse module in npm package

See original GitHub issue

[ ] Regression
[x] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Hi all, I am using Nest for the past year and I love it, kudos for the team!

I have a question and maybe a bug… I am trying to reuse my code in separate repos…

I have a npm package with one module “CommonModule”. In that module I have a controller “MetadataController” and a service “MetadataService”.

Then I have my App that uses that module, but when I include the import CommonModule into the AppModule I have an error:

Error Nest cannot export a component/module that is not a part of the currently processed module (CommonModule). Please verify whether each exported unit is available in this particular context.

common.module:

import { Module } from '@nestjs/common';
import { MetadataController } from './controllers/metadata/metadata.controller';
import { MetadataService } from './services/metadata/metadata.service';

@Module({
  imports: [],
  controllers: [MetadataController],
  providers: [MetadataService],
  exports: [MetadataService],
})
export class CommonModule {}

app.module:

import { CommonModule } from 'my-repo';

@Module({
  imports: [
    CommonModule,
    TypeOrmModule.forRoot(AppModule.getTypeORMConfig()),
    GraphQLModule.forRoot({
      typePaths: ['./src/**/*.graphql'],
      definitions: {
        path: join(
          process.cwd(),
          './src/modules/generated-models/graphql-models.ts',
        ),
        outputAs: 'interface',
      },
      debug: true,
      playground: true,
    }),
  ],
  controllers: [],
  providers: [],
})

Expected behavior

It should be possible to reuse the module.

What is the motivation / use case for changing the behavior?

Reuse modules in external repos.

Environment


Nest version: 5.7.4
 
For Tooling issues:
- Node version: 11.0.0 
- Platform:  Linux

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilmysliwieccommented, Mar 22, 2019

Remove & reinstall all packages. Your npm packages should only define peerDependencies - they shouldn’t have @nestjs/{x} defined inside dependencies so they can share packages among themselves.

1reaction
kamilmysliwieccommented, Mar 21, 2019

You should make @nestjs/common and other @nestjs/{x} packages peer dependencies, so they can share metadata each other.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Easily Share Reusable Modules in Node.js - at Scale
How to easily share and manage NodeJS modules between your projects, services, and apps at any scale — using Git+Bit. Share reusable ......
Read more >
Reusing Node.js modules | React.js Essentials
Notice that npm created a new folder in your ~/snapterest/ directory called node_modules . This is the place where it puts all your...
Read more >
reuse - npm
Reuse different React components to create new ones. Latest version: 2.0.0, last published: 4 years ago. Start using reuse in your project ...
Read more >
Writing reusable modules and libraries in JavaScript - Allround
When it comes to writing libraries or reusable modules from scratch, however, it's not always so clear where to start and how to...
Read more >
how to reuse the root node_modules of the project?
I have try symlink , but it dosen't work. npm log package not found . npm · symlink · node-modules.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found