kevinmarrec / nuxt-pwa-module

⚠️ DEPRECATED ⚠️ Zero config PWA solution for Nuxt 3
MIT License
335 stars 32 forks source link

Issue with nuxi generate #7

Closed jsulpis closed 2 years ago

jsulpis commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

kevinmarrec commented 2 years ago

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

kevinmarrec commented 2 years ago

/cc @pi0 @danielroe

What are the next steps to fix this ? :)

danielroe commented 2 years ago

I opened https://github.com/unjs/nitro/issues/308.

kevinmarrec commented 2 years ago

Great @danielroe thanks !

danielroe commented 2 years ago

See https://github.com/unjs/nitro/issues/308#issuecomment-1169764262 for a recommendation for how to generate the manifest instead which would resolve this issue within this module.

kevinmarrec commented 2 years ago

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

danielroe commented 2 years ago

Exactly.

kevinmarrec commented 2 years ago

Should be fixed by https://github.com/kevinmarrec/nuxt-pwa-module/commit/fa800723f86de346343a4ea434346d79beda6989. 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.