We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
https://github.com/joshuabaker/nextjs-issue-route-get-during-build
Create a route.js or route.ts file with a GET method.
route.js
route.ts
GET
Insert a fetch call.
fetch
Example
import {NextResponse} from 'next/server'; export async function GET(request) { try { const response = await fetch('https://www.example.com', {cache: 'no-store'}); const html = await response.text(); console.log(html); const url = new URL(request.url); const {searchParams} = url; const q = searchParams.get('q') || 'foobar'; console.log(q); return NextResponse.json({q}); } catch (e) { console.log(e); return NextResponse.json({e}); } }
The build often fails as the method is executed, meaning certain env vars, target paths, etc. are not present.
> nextjs-issue-route-get-during-build@0.1.0 build /nextjs-issue-route-get-during-build > next build ▲ Next.js 14.3.0-canary.49 Creating an optimized production build ... ✓ Compiled successfully ✓ Linting and checking validity of types ✓ Collecting page data Generating static pages (0/3) [ ]q [Error]: Dynamic server usage: no-store fetch https://www.example.com / at /nextjs-issue-route-get-during-build/node_modules/.pnpm/next@14.3.0-canary.49_react-dom@19.0.0-beta-4508873393-20240430_react@19.0.0-beta-4508873393-_dfz3r4pybkkgpcxdwvzblb26rm/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:31602 at /nextjs-issue-route-get-during-build/node_modules/.pnpm/next@14.3.0-canary.49_react-dom@19.0.0-beta-4508873393-20240430_react@19.0.0-beta-4508873393-_dfz3r4pybkkgpcxdwvzblb26rm/node_modules/next/dist/server/lib/trace/tracer.js:159:36 at NoopContextManager.with (/nextjs-issue-route-get-during-build/node_modules/.pnpm/next@14.3.0-canary.49_react-dom@19.0.0-beta-4508873393-20240430_react@19.0.0-beta-4508873393-_dfz3r4pybkkgpcxdwvzblb26rm/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7062) at ContextAPI.with (/nextjs-issue-route-get-during-build/node_modules/.pnpm/next@14.3.0-canary.49_react-dom@19.0.0-beta-4508873393-20240430_react@19.0.0-beta-4508873393-_dfz3r4pybkkgpcxdwvzblb26rm/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:518) at NoopTracer.startActiveSpan (/nextjs-issue-route-get-during-build/node_modules/.pnpm/next@14.3.0-canary.49_react-dom@19.0.0-beta-4508873393-20240430_react@19.0.0-beta-4508873393-_dfz3r4pybkkgpcxdwvzblb26rm/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18093) at ProxyTracer.startActiveSpan (/nextjs-issue-route-get-during-build/node_modules/.pnpm/next@14.3.0-canary.49_react-dom@19.0.0-beta-4508873393-20240430_react@19.0.0-beta-4508873393-_dfz3r4pybkkgpcxdwvzblb26rm/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18854) at /nextjs-issue-route-get-during-build/node_modules/.pnpm/next@14.3.0-canary.49_react-dom@19.0.0-beta-4508873393-20240430_react@19.0.0-beta-4508873393-_dfz3r4pybkkgpcxdwvzblb26rm/node_modules/next/dist/server/lib/trace/tracer.js:141:103 at NoopContextManager.with (/nextjs-issue-route-get-during-build/node_modules/.pnpm/next@14.3.0-canary.49_react-dom@19.0.0-beta-4508873393-20240430_react@19.0.0-beta-4508873393-_dfz3r4pybkkgpcxdwvzblb26rm/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7062) at ContextAPI.with (/nextjs-issue-route-get-during-build/node_modules/.pnpm/next@14.3.0-canary.49_react-dom@19.0.0-beta-4508873393-20240430_react@19.0.0-beta-4508873393-_dfz3r4pybkkgpcxdwvzblb26rm/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:518) at NextTracerImpl.trace (/nextjs-issue-route-get-during-build/node_modules/.pnpm/next@14.3.0-canary.49_react-dom@19.0.0-beta-4508873393-20240430_react@19.0.0-beta-4508873393-_dfz3r4pybkkgpcxdwvzblb26rm/node_modules/next/dist/server/lib/trace/tracer.js:141:28) { description: 'no-store fetch https://www.example.com /', digest: 'DYNAMIC_SERVER_USAGE' } ✓ Generating static pages (3/3) ✓ Collecting build traces ✓ Finalizing page optimization Route (app) Size First Load JS ─ ƒ / 0 B 0 B + First Load JS shared by all 0 B Route (pages) Size First Load JS ─ ○ /404 190 B 89.8 kB + First Load JS shared by all 89.6 kB ├ chunks/framework-30630bd20ccb7863.js 55.8 kB ├ chunks/main-67974df10d972141.js 32.1 kB └ other shared chunks (total) 1.65 kB ○ (Static) prerendered as static content ƒ (Dynamic) server-rendered on demand
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 Available memory (MB): 65536 Available CPU cores: 10 Binaries: Node: 18.18.2 npm: 9.8.1 Yarn: N/A pnpm: 9.1.0 Relevant Packages: next: 14.2.3 // Latest available version is detected (14.2.3). eslint-config-next: N/A react: 18.3.1 react-dom: 18.3.1 typescript: N/A Next.js Config: output: N/A
Not sure
next build (local), Vercel (Deployed)
#52185 was unduly closed.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Link to the code that reproduces this issue
https://github.com/joshuabaker/nextjs-issue-route-get-during-build
To Reproduce
Create a
route.js
orroute.ts
file with aGET
method.Insert a
fetch
call.Example
Current vs. Expected behavior
The build often fails as the method is executed, meaning certain env vars, target paths, etc. are not present.
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 Available memory (MB): 65536 Available CPU cores: 10 Binaries: Node: 18.18.2 npm: 9.8.1 Yarn: N/A pnpm: 9.1.0 Relevant Packages: next: 14.2.3 // Latest available version is detected (14.2.3). eslint-config-next: N/A react: 18.3.1 react-dom: 18.3.1 typescript: N/A Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next build (local), Vercel (Deployed)
Additional context
#52185 was unduly closed.
The text was updated successfully, but these errors were encountered: