TypeError: this.requestHandler is not a function
Unanswered
ᵗʰᵉ Nexus posted this in #help-forum
I'm making a project using Nest and Next.js:
I have no idea what's causing the error, I've already researched the documentation and I think I did everything right
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import express from 'express';
import next from 'next';
import { resolve } from 'path';
const { NODE_ENV } = process.env;
const PORT = process.env.PORT ?? 3000;
const DEV = NODE_ENV != 'production';
console.log({dir: resolve('../site')})
const app = next({
dir: resolve('../site'),
dev: DEV
})
const handle = app.getRequestHandler();
async function bootstrap(module = false) {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
if(module) {
app.listen(3000);
} else {
const server = express();
server.use('/api', app.getHttpAdapter().getInstance());
server.all('*', (req, res) => {
return handle(req, res);
});
server.listen(PORT, () => {
console.log(`> Ready on port ${PORT}`);
});
}
}
if(DEV){
app.prepare().then(() => {
bootstrap(true);
});
}
else {
bootstrap(false);
}I have no idea what's causing the error, I've already researched the documentation and I think I did everything right
1 Reply
TypeError: this.requestHandler is not a function
at <anonymous> (C:\www\X\node_modules\next\src\server\next.ts:323:19)
at <anonymous> (C:\www\X\server\src\main.ts:33:14)
at Layer.handle [as handle_request] (C:\www\X\node_modules\express\lib\router\layer.js:95:5)
at next (C:\www\X\node_modules\express\lib\router\route.js:149:13)
at <anonymous> (C:\www\X\node_modules\next\src\server\next.ts:323:19)
at <anonymous> (C:\www\X\server\src\main.ts:33:14)
at Layer.handle [as handle_request] (C:\www\X\node_modules\express\lib\router\layer.js:95:5)
at next (C:\www\X\node_modules\express\lib\router\route.js:149:13)