content icon indicating copy to clipboard operation
content copied to clipboard

Content is not loaded after generate

Open cawa-93 opened this issue 3 years ago • 16 comments

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

  1. Open stackblitz
  2. 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.
  3. Run npm run preview
  4. 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

cawa-93 avatar Jun 23 '22 14:06 cawa-93

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?

farnabaz avatar Jun 23 '22 15:06 farnabaz

I experienced the same right now and can confirm npx server ./output/public works for me.

Tahul avatar Jun 24 '22 12:06 Tahul

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

cawa-93 avatar Jun 24 '22 12:06 cawa-93

I encountered the same problem.

vladimirmyshkovski avatar Jun 24 '22 23:06 vladimirmyshkovski

This sounds similar to #1188.

jshimkoski avatar Jul 01 '22 15:07 jshimkoski

Try serving generated files using npx server ./output/public.

Seems that serving with yarn nuxi preview cause 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.

hacknug avatar Jul 05 '22 22:07 hacknug

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?

danielroe avatar Jul 05 '22 23:07 danielroe

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?

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.

hacknug avatar Jul 05 '22 23:07 hacknug

Regarding GitHub pages, can you add the .nojekyll @hacknug ? (https://github.com/nuxt/content/issues/1298#issuecomment-1168376581)

atinux avatar Jul 06 '22 11:07 atinux

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

hacknug avatar Jul 06 '22 11:07 hacknug

Do you have the link of the deployed website on GH pages @hacknug ?

atinux avatar Jul 06 '22 12:07 atinux

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/

hacknug avatar Jul 06 '22 13:07 hacknug

@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.

farnabaz avatar Jul 06 '22 14:07 farnabaz

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 avatar Jul 06 '22 15:07 danielroe

@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

farnabaz avatar Jul 06 '22 15:07 farnabaz

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 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: 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

hacknug avatar Jul 06 '22 19:07 hacknug