AnonymousUser
AnonymousUser

Reputation: 786

KeyError at / 'assets' and ModuleNotFoundError: No module named 'webpack_loader'

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.

Upvotes: 0

Views: 1905

Answers (3)

Prabhat Bhargav
Prabhat Bhargav

Reputation: 123

In order to use django-webpack-loader>=1.0.0, you must ensure that [email protected] is being used on the JavaScript side.

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

This will surely work for you!

Upvotes: 0

AnonymousUser
AnonymousUser

Reputation: 786

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

Upvotes: 1

Daniel Butler
Daniel Butler

Reputation: 3726

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

Upvotes: 2

Related Questions