question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fail fetching getServerSideProps with basePath

See original GitHub issue

Bug report

Describe the bug

next 9.5.0 issue

After I setuped next.config.js like below,

assetPrefix: "/resources/20200728145115"
basePath: "/ssr"

when I tried to change path by router, fetching getServerSideProps was failed with 404 error.

So I checked data fetch url, it contains assetPrefix instead of basePath. /resources/20200728145115/_next/data/LzktM7sKix9_y5d3dr7ph/[pageRoute]

https://github.com/vercel/next.js/blob/d33dbea8dc684003a8d7babce58b60140089c6e1/packages/next/next-server/lib/router/router.ts#L696-L702

https://github.com/vercel/next.js/blob/d33dbea8dc684003a8d7babce58b60140089c6e1/packages/next/client/page-loader.js#L114-L127

System information

Version of Next.js: 9.5.0 Version of Node.js: 10.13.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
duvholtcommented, Jul 28, 2020

I’m using assetPrefix for serving js/css from a different host than the Next.js server is running on. Since getServerSideProps is executed for each request I wouldn’t expect this to be served from the same location as static files.

For example:

basePath: "/basepath",
assetPrefix: "https://mycdn.example.com/app_path/"

The user visits https://myapp.example.com/basepath/page Which loads js like this as expected https://mycdn.example.com/app_path/_next/static/chunks/pages/(...).js And I would expect getServerSideProps requests to look like this: https://myapp.example.com/basepath/_next/data/(...).json But instead they end up looking like this: https://mycdn.example.com/app_path/_next/data/(...).json

Since mycdn.example.com is just serving a folder with staticfiles this can’t work.

In #11992 it looks like people are trying to use assetPrefix as basePath IMO which kinda makes sense as basePath support was just released.

3reactions
Timercommented, Jul 30, 2020

This was just fixed in 9.5.1, please upgrade!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Fetching: getServerSideProps - Next.js
If an error is thrown inside getServerSideProps , it will show the pages/500.js file. Check out the documentation for 500 page to learn...
Read more >
Nextjs failing on getServerSideProps for no reason
When sending https requests, try adding async / await to handle Promises that axios or fetch or httpRequest returns. Here is an example....
Read more >
NextJS / React SSR: 21 Universal Data Fetching Patterns ...
They have clearly stated that fetching data in "getServerSideProps" doesn't scale well with a large number of pages and components.
Read more >
Next.js: The Good, Bad and Ugly - An Idiosyncratic Blog
Next.js exposes APIs that can be use to fetch data and pre-render a ... getServerSideProps is executed on each request sent to the...
Read more >
Data fetching with Next.js and Strapi CMS - LogRocket Blog
//frontend/utils.js const baseUrl = process.env. ... to prerender the page on each request using the data returned by getServerSideProps .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found