vercel / next.js

The React Framework
https://nextjs.org
MIT License
123.18k stars 26.3k forks source link

sitemap.ts not working with custom pageExtensions #54665

Open sauldeleon opened 10 months ago

sauldeleon commented 10 months ago

Verify canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
    Binaries:
      Node: 16.17.0
      npm: 8.15.0
      Yarn: 1.22.19
      pnpm: 7.1.0
    Relevant Packages:
      next: 13.4.19
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.2.2
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App Router

Link to the code that reproduces this issue or a replay of the bug

https://codesandbox.io/p/sandbox/nervous-gould-p2j5xj

To Reproduce

Start app in dev mode yarn dev

Go to path /sitemap.xml

will return 404 not found

if you rename the sitemap.ts to sitemap.next.ts (according to pageExtensions) it will fail as it does not know how to parse it

image

Describe the Bug

When starting the app, and pageExtensions are set in next.config, the sitemap.ts is not working unless you add its extension.

So, in next.config.js

  pageExtensions: ['next.tsx', 'next.ts', 'next.jsx', 'next.js', 'ts'],

and sitemap.ts will work

  pageExtensions: ['next.tsx', 'next.ts', 'next.jsx', 'next.js'],

and sitemap.ts will fail

  pageExtensions: ['next.tsx', 'next.ts', 'next.jsx', 'next.js'],

and sitemap.next.ts will fail

I guess that as sitemap file is a file threated by next framework, it could be handled the same way as layout, page... etc

Maybe this is not a bug, it is a feature request. Apologize in that case and please move the issue to its respective category.

Expected Behavior

When you have pageExtensions enabled, those rules should apply to sitemap as well as other nextJS reserved files

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1634

naveen-bharathi commented 9 months ago

53328 Same issue with opengraph images as well.

Shubhdeep12 commented 9 months ago

Hi @balazsorban44, I just checked this bug and it seems like there is an issue while checking whether the page path is dynamic or not using pageExtensions.

I would love to work on this and I have a first draft of the solution ready. I would like to raise a PR for this.