-
Notifications
You must be signed in to change notification settings - Fork 342
Description
I'm updating a project to Django 4 and after updating both django-webpack-loader and webpack-bundle-tracker to 1.6.0 (migrating from v0.6.0), the render_bundle tag is failing with a TypeError exception when loading CSS files.
django-webpack-loader/webpack_loader/loader.py
Lines 54 to 63 in b9ac297
| def filter_chunks(self, chunks): | |
| filtered_chunks = [] | |
| for chunk in chunks: | |
| ignore = any(regex.match(chunk) | |
| for regex in self.config['ignores']) | |
| if not ignore: | |
| filtered_chunks.append(chunk) | |
| return filtered_chunks |
In filter_chunks, chunk is expected to be a string but in my case it is a dict, so it raises TypeError when performing regex.match(chunk). In my case, chunks is:
>>> chunks
[{'name': 'main.js', 'path': '/home/fabio/neuralmind/eliot/eliot/case_analysis/static/case_analysis/dist/main.js'}]
The webpack-stats.json content is:
{
"status": "done",
"chunks": {
"main": [
{
"name": "main.js",
"path": "/home/fabio/neuralmind/eliot/eliot/case_analysis/static/case_analysis/dist/main.js"
}
]
}
}
My configs are:
webpack version: 4.46.0
Django template tag:
{% render_bundle 'main' 'css' %}
webpack.config.js:
const path = require('path');
const BundleTracker = require('webpack-bundle-tracker');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
mode: 'production',
entry: path.resolve(__dirname, './js-src/index'),
output: {
path: path.resolve(
__dirname,
'./eliot/case_analysis/static/case_analysis/dist'
),
filename: 'main.js',
},
plugins: [
new CleanWebpackPlugin(), //clean dist folder before building new files
new BundleTracker({
path: path.resolve(path.join(__dirname, './eliot')),
filename: 'webpack-stats.json',
}),
],
resolve: {
alias: {
nm: path.resolve(__dirname, 'node_modules'),
},
modules: [
path.resolve(__dirname, 'js-src'),
path.resolve(__dirname, 'node_modules'),
],
},
resolveLoader: {
modules: [path.resolve(__dirname, 'node_modules')],
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
options: {
presets: [
path.resolve(__dirname, 'node_modules', '@babel/preset-react'),
],
},
exclude: /node_modules/,
},
],
},
};
settings.py:
WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': 'dist/',
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
}
}
I searched through READMEs and issues in both repositories but could not solve this issue, so any help will be appreciated.
Thanks in advance