Skip to content

Next.js 9 Name conflict: 404 for files/folders in pages that start with api #7991

@khasty720

Description

@khasty720

Bug report

Describe the bug

There is a naming conflict bug for files or folders in the root of /pages that start with api i.e. /pages/api-test.js or /pages/api-test/index.js that results in a 404. This bug seems to be result of this line of code /packages/next/build/entries.ts. Files or folders that begin with the name api in the root of the /pages folder receive the following error in the console:

Failed to load resource: the server responded with a status of 404 (Not Found)

Additionally clicking on a element with an onClick event is unresponsive. Example /pages/api-test.js.

To Reproduce

Repository
https://github.com/khasty720/next-js-api-name-conflict

Live Example
https://nextjs-iv9d3ozsv.now.sh/

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to http://localhost:3000 or https://nextjs-iv9d3ozsv.now.sh
  2. Click on 'API Test'
  3. Open console
  4. See error:
Failed to load resource: the server responded with a status of 404 (Not Found)

Expected behavior

Clicking on alert link does not work on http://localhost:3000/api-test. The same Alert component does work on http://localhost:3000/alert-test. The expected behavior is that the page will load and not throw a 404.

System information

  • Version of Next.js: 9.0.1

Additional context

Additional places where /api is referenced:

https://github.com/zeit/next.js/blob/canary/packages/next/build/entries.ts#L71
https://github.com/zeit/next.js/blob/canary/packages/next/build/webpack/loaders/next-serverless-loader.ts#L42
https://github.com/zeit/next.js/blob/canary/packages/next/build/index.ts#L324
https://github.com/zeit/next.js/blob/canary/packages/next/build/entries.ts#L71

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions