admin管理员组文章数量:1332688
I'm working with NX + NestJs. This is my app repo structure:
MyRepo
-> apps
-> NestJsApp1
-> App2
->lib
-> middlewares
-> LoggerMiddleware
I have create Nestjs apps using @nx/nest:app NestJsApp1
, and middleware libs using @nx/node:lib libs/middleware
This is the Logger Middleware.
@Injectable()
export class LoggingMiddleware implements NestMiddleware {
use(req: Request, res: Response, next: NextFunction) {
console.log(`LoggingMiddleware: ${req.method} ${req.url}`);
next();
}
}
This is my NestJSApp1 => AppModule.ts
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { LoggingMiddleware } from 'middlewares';
@Module({
imports: [],
controllers: [],
providers: [],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(LoggingMiddleware)
.forRoutes('*'); // Apply to all routes
}
}
When i server my app, it is working fine. LoggerMiddleware is working properly.
However, when I build my app using command nx run app1:build
, the app is build without any issue,
when then i try to run the main.js from dist, it is throwing error that Middleware Module cannot be found.
I looked into the appModule in dist. This is the build structure:
dist
-> apps
-> app1
-> src
-> appModules.js
-> all other js
-> lib
-> middlewares
-> src
-> index.js
Inside appModule, the middleware is being imported:
var import_middlewares = require("middlewares");
However, if i manually change the path to point the middlewares, it is working.
var import_middlewares = require("../../../libs/middlewares/src");
So any reason why the build is not able to point to the lib correctly ?
本文标签: nestjsNx not able to build with shared middleware libStack Overflow
版权声明:本文标题:nestjs - Nx not able to build with shared middleware lib - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742341879a2456767.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论