kit icon indicating copy to clipboard operation
kit copied to clipboard

Static manifest.json file is overridden with generated file

Open CaptainCodeman opened this issue 1 year ago • 9 comments

Describe the bug

A manifest file added to the static folder i.e. /static/manifest.json is overwritten with a generated SvelteKit file at runtime (happens with adapter-node & adapter-auto).

Reproduction

Add /static/manifest.json file:

{
  "name": "test"
}

Build / run app, request /manifest.json, response is like:

{
  ".svelte-kit/runtime/client/start.js": {
    "file": "_app/immutable/start-1e83f480.js",
    "src": ".svelte-kit/runtime/client/start.js",
    "isEntry": true,
    "imports": [
      "_index-e11c2291.js",
      "_index-b191a7c7.js",
      "_singletons-eca981c1.js"
    ],
    "dynamicImports": [
      "src/routes/__layout.svelte",
      ".svelte-kit/runtime/components/error.svelte",
      "src/routes/folder/[...path]/__layout.svelte",
      "src/routes/about/index.svelte",
      "src/routes/cart/index.svelte",
      "src/routes/folder/[...path]/index.svelte",
      "src/routes/index.svelte",
      "src/routes/photo/[id].svelte"
    ]
  },
  ...

Logs

No response

System Info

System:
    OS: macOS 12.5
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 51.80 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.14.0 - /usr/local/bin/node
    npm: 8.3.1 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 102.1.39.111
    Chrome: 104.0.5112.79
    Chrome Canary: 106.0.5216.0
    Edge: 103.0.1264.77
    Firefox: 102.0.1
    Safari: 15.6
    Safari Technology Preview: 16.0
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.64 
    @sveltejs/adapter-node: next => 1.0.0-next.85 
    @sveltejs/kit: next => 1.0.0-next.401 
    svelte: ^3.49.0 => 3.49.0 
    vite: ^3.0.4 => 3.0.4

Severity

serious, but I can work around it

Additional Information

manifest.json is specifically mentioned as an example of using a static file:

assets — a place to put static files that should have stable URLs and undergo no processing, such as favicon.ico or manifest.json

CaptainCodeman avatar Aug 03 '22 15:08 CaptainCodeman

manifest.json is a static file that Vite creates in the output directory and Vite copies the static assets to the output directory as well, so this seems like an issue that would need changes in Vite to address. Can you file an issue there? See https://github.com/sveltejs/kit#bug-reporting

benmccann avatar Aug 04 '22 02:08 benmccann

It looks like it's a configurable option for Vite, but something SK manages and uses.

It sets it to be generated here, using it here

I don't know if it's used at runtime or just as part of the build process, but maybe a less-likely-to-conflict fixed name could be used instead of the default or a temporary name created, that doesn't exists in the static files?

CaptainCodeman avatar Aug 04 '22 23:08 CaptainCodeman

SvelteKit needs it. We don't control the name. Vite hardcodes that. I think that the real issue isn't the name, but rather that it outputs it to the directory where the results go. It should probably go to a separate configurable directory.

benmccann avatar Aug 04 '22 23:08 benmccann

The name can be set (it defaults to manifest.json if the option is set to true, but it can take a filename as well). So SvelteKit can control what file is used.

https://vitejs.dev/config/build-options.html#build-manifest

It looks like Vite has options to have the assetDir as some place other than outDir so perhaps it's a case of just altering the structure that SK uses?

CaptainCodeman avatar Aug 05 '22 03:08 CaptainCodeman

This is a huge problem for us! Just found! 1.0.0-next.394.

Is there any workaround for now?

frederikhors avatar Aug 07 '22 16:08 frederikhors

Is there any workaround for now?

You could simply name your manifest manifest.webmanifest.

That's the official file extension for webmanifests anyway. https://developer.mozilla.org/de/docs/Web/Manifest

PatrickG avatar Aug 07 '22 16:08 PatrickG

You could simply name your manifest manifest.webmanifest.

It works amazingly! Thanks!

frederikhors avatar Aug 07 '22 17:08 frederikhors

@benmccann are you sure this is a duplicate of that?

frederikhors avatar Aug 08 '22 23:08 frederikhors

You're correct. They're not. I just realized they're slightly different as well

benmccann avatar Aug 08 '22 23:08 benmccann

I just noticed that this bug is affecting kit.svelte.dev

benmccann avatar Aug 11 '22 17:08 benmccann