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

[BUG] Vercel CLI shows Next.js error if page begins with api-, even if Next.js is not present in project #11696

Open
Lissy93 opened this issue Jun 4, 2024 Discussed in #11695 · 1 comment · May be fixed by #11611
Open

Comments

@Lissy93
Copy link

Lissy93 commented Jun 4, 2024

Hey Vercel team 👋
Wondering if someone could spare a second to help me on this:

I've got an Astro project, for which I am using the Vercel CLI.
There's no trace of React or Next.js in my repo project.
Yet when I have a route or component named /src/pages/api-troubleshooting.astro then Vercel CLI starts throwing tons of warnings, saying:

WARN!
When using Next.js, it is recommended to place JavaScript Functions inside of the
pages/api (provided by Next.js) directory instead of api (provided by Vercel). Other
languages (Python, Go, etc) should still go in the api directory.
Learn More: https://nextjs.org/docs/api-routes/introduction

If it helps, here's a screenshot of the issue.


Fix

I've submitted a fix for this in #11611
And would really appreciate a quick review, if any of you had a moment


Cause

Expand Root Cause

This is appears to be caused by fileName.startsWith('pages/api') in

if (
!hasNextApiFiles &&
(fileName.startsWith('pages/api') || fileName.startsWith('src/pages/api'))
) {
hasNextApiFiles = true;
}

Which in turn throws the warning which is being repeatidly displayed in loop

if (
hasNextApiFiles &&
apiBuilders.some(b => isOfficialRuntime('node', b.use))
) {
warnings.push({
code: 'conflicting_files',
message:
'When using Next.js, it is recommended to place JavaScript Functions inside of the `pages/api` (provided by Next.js) directory instead of `api` (provided by Vercel). Other languages (Python, Go, etc) should still go in the `api` directory.',
link: 'https://nextjs.org/docs/api-routes/introduction',
action: 'Learn More',
});
}
}

This feature appears to have been added in #3784 (specifically, this commit specifically).


Bug Report

If you need a formal bug report before this can be reviewed or looked into, I've written one up below:

Bug Report: Vercel CLI shows Next.js error if page begins with `api-`, even if Next.js is not present in project

Summary

When using the Vercel CLI with an Astro app (without React or Next.js), any pages which start with api, such as src/pages/api-setup-guide.astro will throw the following warning

WARN! When using Next.js, it is recommended to place JavaScript Functions inside of the pages/api (provided by Next.js) directory instead of api (provided by Vercel). Other languages (Python, Go, etc) should still go in the api directory.
Learn More: https://nextjs.org/docs/api-routes/introduction

Steps to Reproduce

  1. npm create astro@latest
  2. npx astro add vercel
  3. touch src/pages/api-docs.astro
  4. vercel dev

Minimal reproducible example: https://stackblitz.com/edit/github-yogmzg-d6z7xm

Expected Behavior

No warnings. Because everything is 200 okay :)

Actual Behavior

User sees a barage of warnings from the Vercel CLI, informing them not to put Next.js API routes in Astro pages. This occours on a totally vanillar Astro app, with no traces of either React nor Next.js, just because they have an Astro route beginning with pages/api-XXX

Environment Info

Vercel CLI: 34.2.0
Node: v20.13.1
Astro: 4.8.6
@astrojs/vercel: 7.5.4
OS: Arch Linux, 2024.05.01

Areas Affected

Vercel CLI


Thanks for taking the time to check this out, really appreciate it ❤️
If you need any more details, please let me know, and I'll be happy to help :)

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

Successfully merging a pull request may close this issue.

2 participants
@Lissy93 and others