Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

res.setHeader is not a function When i add new FastifyAdapter() #99

Open
samuelhalim1 opened this issue Dec 10, 2022 · 10 comments
Open

Comments

@samuelhalim1
Copy link

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
@kyle-mccarthy
Copy link
Owner

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?

@samuelhalim1
Copy link
Author

TypeError: res.setHeader is not a function
at NextNodeServer.renderError (/Users/Development/test/node_modules/.pnpm/next@13.0.6_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/server/base-server.js:1047:17)
at NextNodeServer.renderError (/Users/Development/test/node_modules/.pnpm/next@13.0.6_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/server/next-server.js:844:22)
at NextServer.renderError (/Users/Development/test/node_modules/.pnpm/next@13.0.6_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/server/next.js:115:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

@samuelhalim1
Copy link
Author

samuelhalim1 commented Dec 12, 2022

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

@samuelhalim1
Copy link
Author

add some information, that i use

Version

  • @nestjs/platform-fastify: ^9.2.1

@kyle-mccarthy
Copy link
Owner

So it looks like this error is coming from next. Notice that the path /Users/Development/test/node_modules/.pnpm/[next@13.0.6_biqbaboplfbrettd7655fr4n2y](mailto:next@13.0.6_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.

@samuelhalim1
Copy link
Author

samuelhalim1 commented Dec 13, 2022

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?

@tmaus
Copy link

tmaus commented Mar 18, 2023

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)

@indra-yana
Copy link

any update? same problem too

@raychunghk
Copy link

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();

@raychunghk
Copy link

I started a discussion regarding this on Next github discussion
vercel/next.js#51463

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants