django-webpack/django-webpack-loader

KeyError: 'status' when trying to `render_bundle`

bunnymatic opened this issue · 2 comments

On a fresh Django project, I'm running into issues where it appears my webpack bundle is missing the status key and django-webpack-loader is failing to render_bundle

Here is the trimmed traceback.

Internal Server Error: /
Traceback (most recent call last):
  File "/Users/jon/Library/Caches/pypoetry/virtualenvs/django-react-19wCKYUK-py3.9/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/jon/Library/Caches/pypoetry/virtualenvs/django-react-19wCKYUK-py3.9/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/jon/projects/django-react/main/views.py", line 8, in index
    return render(request, "things/index.html", ctx)
...
  File "/Users/jon/Library/Caches/pypoetry/virtualenvs/django-react-19wCKYUK-py3.9/lib/python3.9/site-packages/webpack_loader/templatetags/webpack_loader.py", line 20, in render_bundle
    tags = utils.get_as_tags(
  File "/Users/jon/Library/Caches/pypoetry/virtualenvs/django-react-19wCKYUK-py3.9/lib/python3.9/site-packages/webpack_loader/utils.py", line 61, in get_as_tags
    bundle = _get_bundle(bundle_name, extension, config)
  File "/Users/jon/Library/Caches/pypoetry/virtualenvs/django-react-19wCKYUK-py3.9/lib/python3.9/site-packages/webpack_loader/utils.py", line 39, in _get_bundle
    bundle = get_loader(config).get_bundle(bundle_name)
  File "/Users/jon/Library/Caches/pypoetry/virtualenvs/django-react-19wCKYUK-py3.9/lib/python3.9/site-packages/webpack_loader/loader.py", line 80, in get_bundle
    while assets['status'] == 'compile' and not timed_out:
KeyError: 'status'

If I look at my stats.json file, there is no key status. The react side was started with CRA and using webpack-bundle-analyzer to generate the stats.json file with this configuration

const BundleAnalyzerPlugin =
  require("webpack-bundle-analyzer").BundleAnalyzerPlugin;

module.exports = function () {
  return {
    webpack: {
      plugins: [new BundleAnalyzerPlugin({ analyzerMode: "json", generateStatsFile: true })],
    },
  };
};

I can't find any options on this plugin to add the status column. I wonder if this is a standard key or if this plugin might be a bit more flexible if it didn't require that key to be there.

# pyproject.toml - the related bits
python = "^3.9"
Django = "^4.0.1"
django-webpack-loader = "^1.4.1"

Any ideas?

Here's a screenshot of the folded stats.json - I can add the full contents if that would help, it seemed like maybe overkill. But you can see that there is no top level status key.

image

Hi @bunnymatic, it looks like you're using webpack-bundle-analyzer instead of webpack-bundle-tracker (https://github.com/django-webpack/webpack-bundle-tracker), which is the sibling library we use to generate the stats file. I think you got confused about which library to use. Would you mind trying the latter to check if it works?

Wow. That was dumb.

Thanks. That was indeed the problem.