Skip to content

res.hasHeader is not a function #34929

@mandar1jn

Description

@mandar1jn

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64      
      Version: Windows 10 Home
    Binaries:
      Node: 17.4.0
      npm: 8.3.1
      Yarn: 1.22.17
      pnpm: N/A
    Relevant packages:
      next: 12.1.1-canary.4
      react: 17.0.2
      react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

next start and next dev

Describe the Bug

Some function on the res object throws the following error:

TypeError: res.hasHeader is not a function
    at Object.setRevalidateHeaders (C:\Users\Erik de Vlaam\Desktop\personal-website\node_modules\next\dist\server\send-payload\revalidate-headers.js:8:37)
    at Object.sendRenderResult (C:\Users\Erik de Vlaam\Desktop\personal-website\node_modules\next\dist\server\send-payload\index.js:43:33)

Expected Behavior

I guess it is expected for the functions to just work(?) and not throw an error

To Reproduce

The following page should be good to reproduce. The folder structure should be easy to resolve from this code.

import fs from "fs";
import { GetServerSideProps } from "next";
import path from "path";
import { FunctionComponent } from "react";

export const getServerSideProps: GetServerSideProps = async (context) => {

	const id = context.params!.id!.toString();

	const filePath = path.join("images", id);

	if(!fs.existsSync(filePath))
	{
		return {
			notFound: true
		}
	}

	context.res.setHeader("content-type", "image/png");
	context.res.write(fs.readFileSync(path.join("images", id)));
	context.res.end();

	return {
		props: {

		}
	}

}

const Images: FunctionComponent = () =>
{
	return <></>
}

export default Images;"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Linking and NavigatingRelated to Next.js linking (e.g., <Link>) and navigation.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions