MrBin99 / django-vite

Integration of ViteJS in a Django project.
Apache License 2.0
575 stars 72 forks source link

Missing staticfiles manifest entry for '/assets/main-130a948e.js' #85

Open joonjeong opened 1 year ago

joonjeong commented 1 year ago

Hi, I'd like to report error after upgrade django-vite.

Previously, I've been used 2.0.2 version and I recently upgrade django-vite to 2.1.2. After I upgrade, I'm meeting Missing staticfiles manifest entry error like this.

  File "/Users/user/workspace/app-portal/app-control-plane/.venv/lib/python3.10/site-packages/django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/Users/user/workspace/app-portal/app-control-plane/.venv/lib/python3.10/site-packages/django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/Users/user/workspace/app-portal/app-control-plane/.venv/lib/python3.10/site-packages/django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "/Users/user/workspace/app-portal/app-control-plane/.venv/lib/python3.10/site-packages/django/template/library.py", line 237, in render
    output = self.func(*resolved_args, **resolved_kwargs)
  File "/Users/user/workspace/app-portal/app-control-plane/.venv/lib/python3.10/site-packages/django/utils/safestring.py", line 53, in wrapper
    return safety_marker(func(*args, **kwargs))
  File "/Users/user/workspace/app-portal/app-control-plane/.venv/lib/python3.10/site-packages/django_vite/templatetags/django_vite.py", line 524, in vite_asset
    return DjangoViteAssetLoader.instance().generate_vite_asset(path, **kwargs)
  File "/Users/user/workspace/app-portal/app-control-plane/.venv/lib/python3.10/site-packages/django_vite/templatetags/django_vite.py", line 142, in generate_vite_asset
    DjangoViteAssetLoader._generate_production_server_url(
  File "/Users/user/workspace/app-portal/app-control-plane/.venv/lib/python3.10/site-packages/django_vite/templatetags/django_vite.py", line 467, in _generate_production_server_url
    return staticfiles_storage.url(production_server_url)
  File "/Users/user/workspace/app-portal/app-control-plane/.venv/lib/python3.10/site-packages/django/contrib/staticfiles/storage.py", line 203, in url
    return self._url(self.stored_name, name, force)
  File "/Users/user/workspace/app-portal/app-control-plane/.venv/lib/python3.10/site-packages/django/contrib/staticfiles/storage.py", line 182, in _url
    hashed_name = hashed_name_func(*args)
  File "/Users/user/workspace/app-portal/app-control-plane/.venv/lib/python3.10/site-packages/django/contrib/staticfiles/storage.py", line 513, in stored_name
    raise ValueError(
ValueError: Missing staticfiles manifest entry for '/assets/main-130a948e.js'
2023-06-13 13:46:32,488 [   ERROR] "GET /ranking/qps/ HTTP/1.1" 500 145
emab commented 1 year ago

This could be due to #81 as I saw the same error. You're probably seeing this error because your asset name in your vite manifest is actually assets/main-130a948e.js but the slash is being prepended.

If you can use the code on master it will verify if this is the problem.

matias-iturburu commented 1 year ago

I have this vite.config.js


const rollupOptions = {

    input: {
        main: resolve("./src/assets/main.js"),
    },

    output: {
        entryFileNames: "[name].js",
        chunkFileNames: undefined,
        assetFileNames: '[name][extname]'

    },
};

module.exports = {
    plugins: [],
    root: resolve("./src/assets"),
    base: "/static/",
    assetsDir: "public",
    resolve: {
        extensions: [".js", ".json"],
    },
    build: {
        outDir: resolve("./src/mpm/static"),
        manifest: true,
        target: "es2015",
        sourcemap: true,
        rollupOptions
    },
};

Notice how the hash is removed. It build this manifest:

{
  "main.js": {
    "file": "main.js",
    "src": "main.js",
    "isEntry": true,
    "css": [
      "main.css"
    ]
  },
  "main.css": {
    "file": "main.css",
    "src": "main.css"
  }
}

And I'm linking the stylesheet as :

<link rel="stylesheet" href="{% vite_asset_url 'main.css' %}">

Which works on on development mode. But fails in production mode with the same error than OP. I'll create a separate issue if needed. But the error is exact the same:

File "/usr/local/lib/python3.10/site-packages/django/contrib/staticfiles/storage.py", line 513, in stored_name
     raise ValueError(
ValueError: Missing staticfiles manifest entry for 'main.css'