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:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Remove & reinstall all packages. Your npm packages should only define
peerDependencies
- they shouldn’t have@nestjs/{x}
defined insidedependencies
so they can share packages among themselves.You should make
@nestjs/common
and other@nestjs/{x}
packages peer dependencies, so they can share metadata each other.