Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Issue with nuxi generate #7

Closed
jsulpis opened this issue May 31, 2022 · 14 comments
Closed

Issue with nuxi generate #7

jsulpis opened this issue May 31, 2022 · 14 comments
Labels
bug Something isn't working upstream This issue should be fixed upstream

Comments

@jsulpis
Copy link

jsulpis commented May 31, 2022

Hello,
first of all, thank you for this module !
I would like to use it with static generation and this does not seem to work.

In your repo, when I run pnpm nuxi generate example, I get the following error :

ℹ Prerendering 1 initial routes with crawler
  ├─ / (43ms)
  ├─ /manifest.f92523ca.json (undefinedms) (Error: EEXIST: file already exists, mkdir '/path/to/nuxt-pwa-module/example/.output/public/manifest.f92523ca.json')  

The build output seems to be fine. However, when I move the app.vue file into a pages folder and rename it to index.vue (closer to a real world configuration), with the same command I get this error :

ℹ Prerendering 1 initial routes with crawler
  ├─ / (48ms)
  ├─ /manifest.f92523ca.json (4ms) (Error: [404] Page not found: /manifest.f92523ca.json)  

In this case, the content of the manifest file is corrupted, so the app is not installable.
Maybe the manifest file should be moved into the assets folder ? or ignored during the prerendering somehow ?

I am OK to contribute if it helps you and if you give me some indications :)

@kevinmarrec kevinmarrec added the bug Something isn't working label May 31, 2022
@kevinmarrec
Copy link
Owner

kevinmarrec commented May 31, 2022

@jsulpis I didn't play a lot with Nuxt 3 generate, but there is indeed an issue.

I still think we should keep manifest.json on baseURL, as there's already a manifest.json in assets generated by Nuxt which gives information about the assets (js / css).

But in the other hand, it seems Nuxt 3 recognize any href as a route, so it tries to navigate to the manifest.json somehow.

I'll need to have a closer look, as I don't really want to have to move it to assets and rename it to pwa.manifest.json to not have conflict with the other manifest.json.

Feel free to suggest a fix if you find some :)

EDIT: I tried to move it to assets, it does not fix the issue :

image

@kevinmarrec
Copy link
Owner

I think this is done by nitro crawler : https://github.com/nuxt/framework/blob/main/packages/nuxt/src/core/nitro.ts#L52

@pi0 Do you have a clue about why Nitro is trying to crawl the manifest file ? :)

@jsulpis
Copy link
Author

jsulpis commented May 31, 2022

I wonder if it could be an issue in nuxt3 / nitro, because I tried to remove the link tag at the end of the meta.ts file (which removed the error because there is no link to the manifest), then I added said link in nuxt.config.ts:

app: {
    buildAssetsDir: '/assets/',
    head: {
      link: [
        {'rel': 'manifest', href: '/assets/manifest.f92523ca.json'}
      ]
    }
  },

and the same 404 error comes back on the manifest file. This does not seem right to me

@kevinmarrec
Copy link
Owner

Your configuration from your nuxt.config is exactly what is doing this module here https://github.com/kevinmarrec/nuxt-pwa-module/blob/main/src/meta.ts#L160, so you should expect same error :)

@kevinmarrec
Copy link
Owner

kevinmarrec commented May 31, 2022

This is just about Nitro trying to crawl a file as a route, I'd say.

The manifest link is grabbed from HTML :
https://github.com/unjs/nitro/blob/main/src/prerender.ts#L112

Then it is not ignored cause json has been tagged as allowed extension :
https://github.com/unjs/nitro/blob/main/src/prerender.ts#L10
https://github.com/unjs/nitro/blob/main/src/prerender.ts#L122

Let's wait for some @pi0 thoughts about this.

@bendwarn
Copy link

bendwarn commented Jun 2, 2022

Not module issue. Prerender is experimental. If ssr is false, html will be clean and get rid of error.

@kevinmarrec kevinmarrec added the wontfix This will not be worked on label Jun 4, 2022
@kevinmarrec
Copy link
Owner

kevinmarrec commented Jun 7, 2022

@jsulpis

Closing as the problem isn't caused by this module implementation but needs to be fixed upstream.

One workaround is disabling crawler in nuxt.config :

import { defineNuxtConfig } from 'nuxt'

export default defineNuxtConfig({
  generate: {
    crawler: false
  }
})

This will prevent nitro (used by Nuxt 3) to crawl links found inside generated pages.

@pi0 @danielroe
We should consider doing two things :

  • Pass generate.exclude nuxt configuration to Nitro prerender to be able to opt out routes before and after crawling.
  • Makes Nitro crawler link regex better : Avoid rel: 'manifest' links.

@kevinmarrec
Copy link
Owner

/cc @pi0 @danielroe

What are the next steps to fix this ? :)

@danielroe
Copy link
Contributor

danielroe commented Jun 28, 2022

I opened nitrojs/nitro#308.

@kevinmarrec
Copy link
Owner

Great @danielroe thanks !

@danielroe
Copy link
Contributor

danielroe commented Jul 4, 2022

See nitrojs/nitro#308 (comment) for a recommendation for how to generate the manifest instead which would resolve this issue within this module.

@kevinmarrec
Copy link
Owner

kevinmarrec commented Jul 4, 2022

@danielroe About the possible fix, It means serving manifest.json through a Nuxt Server (Nitro) API endpoint ? i.e. a h3 event handler ?

@danielroe
Copy link
Contributor

Exactly.

@kevinmarrec
Copy link
Owner

kevinmarrec commented Jul 22, 2022

Should be fixed by fa80072.
I've tested to local serve a generated Nuxt 3 PWA app (with nuxi generate) and it sounds to work well.

Will be available in next release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working upstream This issue should be fixed upstream
Projects
None yet
Development

No branches or pull requests

4 participants