content
content copied to clipboard
Content is not loaded after generate
Environment
- Operating System:
Linux - Node Version:
v16.15.0 - Nuxt Version:
3.0.0-rc.4 - Package Manager:
[email protected] - Builder:
vite - User Config:
css,build,typescript,modules,components - Runtime Modules:
@nuxt/[email protected],unplugin-icons/nuxt - Build Modules:
-
Reproduction
https://stackblitz.com/edit/github-jdzmbl?file=components/Feed.vue
- Open stackblitz
- There are generated .output by
npm run generate. I don't know how to execute the generation command in stackblits, so I generated the files locally and put them in the project. You should get the same result by regenerating. - Run
npm run preview - On
/path you should see valid JSON array with content. But on subpath you should see HTML instead JSON
Describe the bug
I have several pages to display the content. In the desktop, the filtered JSON is displayed correctly on each page. However, after generating the site, HTML is returned instead of JSON
Additional context
No response
Logs
No response
Try serving generated files using npx serve ./output/public.
Seems that serving with yarn nuxi preview cause this issue.
@danielroe Do you know what could have caused this issue?
I experienced the same right now and can confirm npx server ./output/public works for me.
I encountered this problem in the production of netlify. The dev environment works correctly, however, deployed project on netlify is broken. Netlify build command is nuxt generate. I not shure how netlify serve project and how configure it
I encountered the same problem.
This sounds similar to #1188.
Try serving generated files using
npx server ./output/public.Seems that serving with
yarn nuxi previewcause this issue.@danielroe Do you know what could have caused this issue?
The issue seems to be caused by one of the options yarn preview passes to npx serve. Instead of doing npx serve .output/public it does npx serve -s .output/public. Removing that -s from nitro.json's command.preview allows you to reproduce and run yarn preview without any issues.
This seems to be the cause of issue I was experiencing in #1335. Although I'm not 100% sure if there's not another moving piece here.
EDIT: Seems to work fine when deploying to both Netlify and Vercel so it's probably just a bug on the nitro preset or similar.
The -s enables fallback to index.html if it doesn't find an exact match. Maybe there is a bug in serve with query parameters?
The
-senables fallback toindex.htmlif it doesn't find an exact match. Maybe there is a bug inservewith query parameters?
Looks like it, yeah. I edited my comment to add it works with both Netlify and Vercel so it probably only affects one of the nitro presets.
I'm actually experiencing this issue in GitHub pages so it may also be something a little more obscure. I can share the repo in case that helps but I think it's probably being caused by the same lines of code.
Regarding GitHub pages, can you add the .nojekyll @hacknug ? (https://github.com/nuxt/content/issues/1298#issuecomment-1168376581)
Regarding GitHub pages, can you add the
.nojekyll@hacknug ? (#1298 (comment))
It's already there. You can check the gh-pages branch of the repo here: https://github.com/hacknug/romi-project/tree/gh-pages
Do you have the link of the deployed website on GH pages @hacknug ?
Do you have the link of the deployed website on GH pages @hacknug ?
I forgot to add that, sorry. Here it is: https://hacknug.github.io/romi-project/
@Atinux @hacknug
I believe this is an upstream issue related to Nitro pre-renderer. Nitro should remove baseURL before generating the route. You can see that it generated romi-project directory.
In that case, it's probably been resolved by https://github.com/unjs/nitro/pull/289 (nitropack 0.4.9) - you are still on 0.4.8 and can pull in the latest nitropack with yarn upgrade nuxt or npm upgrade nuxt.
@danielroe This will not fix the whole issue, I updated nuxt and nitro to the latest versions. we should also remove baseURL from routes before adding them to the routes list here
Created a PR for it: https://github.com/unjs/nitro/pull/329
In that case, it's probably been resolved by unjs/nitro#289 (nitropack 0.4.9) - you are still on 0.4.8 and can pull in the latest nitropack with
yarn upgrade nuxtornpm upgrade nuxt.
@danielroe This will not fix the whole issue, I updated nuxt and nitro to the latest versions. we should also remove
baseURLfrom routes before adding them to the routes list hereCreated a PR for it: unjs/nitro#329
Seems like both of you were right. Updating to [email protected] fixed the issue on GitHub Pages so huge thank you for that!
The only issue left would be the one caused by the -s flag. The other reproductions provided by OPs in #1281 (this issue) and #1188 don't have a custom baseUrl on their config files so perhaps there will be something else needed to fix it besides the changes in https://github.com/unjs/nitro/pull/329