0

When I am at http://127.0.0.1:8000/ I'm getting this error

KeyError at /

'assets'


In settings.py

Installed apps

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    #own
    'rest_framework',
    'rest_framework.authtoken',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',    

    'rest_auth',
    'rest_auth.registration',

    'crispy_forms',
    'webpack_loader',

    'users',
    'questions',

Webpack Loader

    WEBPACK_LOADER = {
        'DEFAULT': {
            'BUNDLE_DIR_NAME': 'dist/',
            'STATS_FILE': os.path.join(BASE_DIR, 'frontend', 'webpack-stats.json'),
        }
}

In templates folder (index.html)

{% load render_bundle from webpack_loader %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QuestionTime</title>
</head>
<body>
    
    <h1>Vue JS</h1>

    <div id="app"></div>

    {% render_bundle 'app' %}

</body>
</html>

I also have the vue.config.js file

(OLD see UPDATED)

In the terminal it says this

asset = assets['assets'][chunk]

KeyError: 'assets'

Terminal (UPDATED)

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'webpack_loader'

UPDATED: Uninstalled Django-webpack5-loader since it didn't do what I hoped.

But now I get another error

See above "Terminal (UPDATED)"

UPDATE 2

All errors are gone now, only issue is that, my vue doesn't show up in the browser.

AnonymousUser
  • 690
  • 7
  • 26
  • Could you paste the entire error displayed in the terminal? – Daniel Butler Jun 10 '21 at 05:41
  • Do you know where `asset = assets['assets'][chunk]` is in your code? It's trying to grab a key `'assets'` and not finding it in the `assets` object. – Jarad Jun 10 '21 at 05:51

3 Answers3

2

The error seems to be in the webpack package. This answer should help: Django Webpack Loader: "Assets" KeyError?

Daniel Butler
  • 3,239
  • 2
  • 24
  • 37
  • I downloaded *django-webpack5-loader* but then I didn't get vue on the browser only the html, also I installed *django-webpack-loader==0.7.0* – AnonymousUser Jun 10 '21 at 06:23
  • I'm getting this error: File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 984, in _find_and_load_unlocked ModuleNotFoundError: No module named 'webpack_loader' – AnonymousUser Jun 10 '21 at 07:00
  • It seems like you’ve uninstalled webpack_loader but didn’t reinstall the version that does not have the bug. – Daniel Butler Jun 10 '21 at 07:53
  • I have already done this *pip install django-webpack-loader==0.7.0* – AnonymousUser Jun 10 '21 at 07:56
  • Do you have webpack_loader in your installed apps in settings.py? – Daniel Butler Jun 10 '21 at 08:08
  • Fixed the issue, but I'm not getting my vue code in the browser now. – AnonymousUser Jun 11 '21 at 03:47
  • That is odd it sounds like the webpack isn’t being used at all – Daniel Butler Jun 12 '21 at 02:08
1

ModuleNotFoundError: No module named 'webpack_loader' (SOLVED)

If you already have done pip install django-webpack-loader==0.7.0

Do like this:

First do:

pip uninstall django-webpack-loader==0.7.0

or

pip uninstall django-webpack-loader

After that tap y and then enter

then:

pip install django-webpack-loader==0.7.0

AnonymousUser
  • 690
  • 7
  • 26
0

In order to use django-webpack-loader>=1.0.0, you must ensure that webpack-bundle-tracker@1.0.0 is being used on the JavaScript side.

https://pypi.org/project/django-webpack-loader/

This will surely work for you!