nest-next
nest-next copied to clipboard
res.setHeader is not a function When i add new FastifyAdapter()
Describe the bug
If i put new FastifyAdapter()
like this
const app = await NestFactory.create<NestFastifyApplication>( AppModule, new FastifyAdapter(), )
it will return error when i access localhost:3000
res.setHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate"); ^ TypeError: res.setHeader is not a function
Is it can't support fastify adapter? Because i serve static files from my server use the fastify adapter
Version
- next.js: 13.0.6
- nest: 9.0.0
- nest-next: 10.0.0
It works correctly with the fastify adapter. This library doesn't actually make any calls to setHeader
on the response, so I think that your problem is coming from your application code or perhaps nextjs. Whre does the stacktrace say that the setHeader call is?
TypeError: res.setHeader is not a function at NextNodeServer.renderError (/Users/Development/test/node_modules/.pnpm/[email protected]_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/server/base-server.js:1047:17) at NextNodeServer.renderError (/Users/Development/test/node_modules/.pnpm/[email protected]_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/server/next-server.js:844:22) at NextServer.renderError (/Users/Development/test/node_modules/.pnpm/[email protected]_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/server/next.js:115:23) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Even when i try to add FasitifyAdapter on this Example https://github.com/yakovlev-alexey/nest-next-example
The error is same.. So i assume that the error isn't came from my next or nest app
just make sure u guys know @yakovlev-alexey @kyle-mccarthy
add some information, that i use
Version
- @nestjs/platform-fastify: ^9.2.1
So it looks like this error is coming from next. Notice that the path /Users/Development/test/node_modules/.pnpm/[[email protected]_biqbaboplfbrettd7655fr4n2y](mailto:[email protected]_biqbaboplfbrettd7655fr4n2y)/node_modules/next/dist/server/base-server.js:1047:17
points to the base server file in the next package.
Since next 13 is effectively still in beta, I don't plan to add support for it until it is stabilized. You should be able to continue to use next 12 without issue.
Allrite.. so right now the project is running With Version
- next: ^12.3.4
- @nestjs/platform-fastify: ^8.0.0
But when i upgrade the platform-satisfy version to ^9.2.1
.. It just show a blank page
Is it doesn't support 9.2.1 version?
Any update on this topic ?
"@nestjs/common": "^9.3.10",
"@nestjs/config": "^2.3.1",
"@nestjs/core": "^9.3.10",
"@nestjs/platform-express": "^9.3.10",
"@nestjs/platform-fastify": "^9.3.10",
"@nestjs/swagger": "^6.2.1",
"nest-next": "^10.1.0",
"next": "12.3.3",
"react": "18.2.0",
"react-dom": "18.2.0",
error - unhandledRejection: TypeError: res.setHeader is not a function at DevServer.renderError (/Users/thor/Documents/Development/private/nft-certification/node_modules/next/server/base-server.ts:1786:11) at DevServer.renderError (/Users/thor/Documents/Development/private/nft-certification/node_modules/next/server/next-server.ts:1368:18) at NextServer.renderError (/Users/thor/Documents/Development/private/nft-certification/node_modules/next/server/next.ts:100:19) at processTicksAndRejections (node:internal/process/task_queues:95:5)
any update? same problem too
I try next 13.4.x, 12.4.6, platform-fastify 8, 9.x All of the combination does not work. I try to do the setup with express, it works.
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { fastifyStatic } from 'fastify-static';
import { join } from 'path';
import { RenderService } from 'nest-next';
import secureSession from '@fastify/secure-session';
import session from 'express-session';
async function bootstrap() {
const usefastify = false;
if (usefastify) {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
);
app.setGlobalPrefix(`/absproxy/5000`);
await app.register(secureSession, {
secret: 'averylogphrasebiggerthanthirtytwochars',
salt: 'mq9hDxBVDbspDR6n',
});
await app.listen(5000);
}
else {
const app = await NestFactory.create(AppModule);
app.setGlobalPrefix(`/absproxy/5000`);
const service = app.get(RenderService);
app.use(
session({
secret: 'my-secret',
resave: false,
saveUninitialized: false,
}),
);
await app.listen(5000);
}
/* if (module.hot) {
module.hot.accept();
module.hot.dispose(() => app.close());
}*/
}
bootstrap();
I started a discussion regarding this on Next github discussion https://github.com/vercel/next.js/discussions/51463