When build with webpack's 'production' mode - httpAdapterHost is not initialized.
Serg-Mois opened this issue Ā· comments
Hello, I've taken your example https://github.com/nestjs/nest/tree/master/sample/24-serve-static, and added webpack builder in order to bundle everything in one file.
When build with 'production' mode set in webpack - there is an exception in runtime:
24-serve-static>npm run start:prod
> nest-typescript-starter@1.0.0 start:prod \24-serve-static
> node dist/main
[Nest] 1736 - 02/20/2020, 2:20:43 PM [NestFactory] Starting Nest application...
(node:1736) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[Nest] 1736 - 02/20/2020, 2:20:43 PM [l] l dependencies initialized +14ms
(node:1736) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getInstance' of undefined
but, if mode in webpack is commented - everything works fine.
In node_modules@nestjs\serve-static\dist\serve-static.module.js
let ServeStaticModule = ServeStaticModule_1 = class ServeStaticModule {
constructor(ngOptions, loader, httpAdapterHost) {
this.ngOptions = ngOptions;
this.loader = loader;
this.httpAdapterHost = httpAdapterHost;
httpAdapterHost in runtime is
{
httpAdapterHost: {
ioAdapter: null,
globalPrefix: '',
globalPipes: [],
globalFilters: [],
globalInterceptors: [],
globalGuards: [],
globalRequestPipes: [],
globalRequestFilters: [],
globalRequestInterceptors: [],
globalRequestGuards: []
}
see code here.
https://github.com/Serg-Mois/serve_static_webpack_bug
also, when build with webpack - you need explicitly add "fastify-static" into dependencies.
Is there any other way to send index.html if no Controllers were found?
I was trying to make:
@Controller('')
export class ClientController {
@Get('*')
public angularApp(@Res() res: Response): any {
res.sendFile(path.join(__dirname, './client/index.html'));
}
}
and put this Controller as the last one in controllers array of Module , but as described here nestjs/nest#1667 - the order doesn't matter.
Don't use the production mode in webpack to bundle server-side applications. This may cause issues with numerous libraries, including typeorm, sequelize-typescript or NestJS.