You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Everything works fine in dev mode, but fails on npm run export:
Error: only absolute urls are supported
It's clear to me that when running npm run exportnext will run getInitialProps "on the server" ( i don't know any other way of putting it ), and fetch doesn't know how to resolve the file path.
I've seen the Error above mentioned in issue #1213, and one of the solutions given was to form a baseUrl, checking the req parameter to do so:
The problem with this is that the req parameter, though exists, doesn't contain anything helpful. It only contains the url of the page:
{url: '<relative page url>'}
The only example I can find in the docs is fetching post data from an external source. See here:
staticasyncgetInitialProps({ query }){// fetch single post detailconstresponse=awaitfetch(`http://jsonplaceholder.typicode.com/posts/${query.id}`)constpost=awaitresponse.json()return{ ...post}}
The fact that my blog post data is stored in local JSON files makes this difficult. Is there a built-in way to handle this issue using next?
The text was updated successfully, but these errors were encountered:
Actually , this is not a bug but the behavior of static apps.
We don't run a server when doing exports. So, you can't fetch from local routes in your custom server.
May be you can require those files directly inside getInititalProps or use another server.
I am attempting a NextJS powered website/blog that is 100% static as of NextJS v3.
Here is the flow I am trying to achieve:
The flow outlined above is being done similarly to how next-blog is working.
The
post.js
page fetches the specific JSON from/posts
according to thequery.id
:I'm also using a custom Express server to handle the
/posts/:id
route:Everything works fine in
dev
mode, but fails onnpm run export
:It's clear to me that when running
npm run export
next
will rungetInitialProps
"on the server" ( i don't know any other way of putting it ), andfetch
doesn't know how to resolve the file path.I've seen the Error above mentioned in issue #1213, and one of the solutions given was to form a baseUrl, checking the
req
parameter to do so:The problem with this is that the
req
parameter, though exists, doesn't contain anything helpful. It only contains the url of the page:The only example I can find in the docs is fetching post data from an external source. See here:
The fact that my blog post data is stored in local JSON files makes this difficult. Is there a built-in way to handle this issue using
next
?The text was updated successfully, but these errors were encountered: