TL;DR
This article has been updated for Django 4, React 18 and Webpack 5. You can download the finished code from my GitHub repository. ...
For further actions, you may consider blocking this person and/or reporting abuse
Hey, thanks for the article, that really helped me!
I had to bump the
webpack-bundle-tracker
version to1.0.0
because of a breaking change in the python packagewebpack_loader
specifically made to match the v1 of the js lib (you see the nice circle here :o).thanks man!
Hi Zack, Great Post! I ended up having to add
to the config passed to the BundleTracker constructor in my webpack.config.js
by default my webstat-stats.json was being generated with:
which got prepended as
I just compared your package.json to mine, and perhaps this has to do with running:
npm install --save-dev webpack webpack-cli
(without specifing versions) installed:several months ago, but running it today installed
? Just a guess
I just tested this and yes, it looks like with the new versions of
webpack
andwebpack-cli
, the use ofpublicPath
is required to make Django serve the bundle at the correct url. I've updated the article and the GitHub repo. Thanks for pointing this out!Thanks but it fails:
Thanks for the tutorial! I had problems finding the
static
files too. I fixed it bypublicPath: "static/frontend"
topublicPath: "/static/frontend"
inwebpack.config.js
.STATIC_URL = "static/"
toSTATIC_URL = "/static/"
.Great article! Thank you for sharing.
I'm getting an error from the server console and browser console when the template is called. Has anyone come across this?
Browser Console:
Server Console:
Hi, Zach! I'm trying to figure out how to make this all work with a Typescript setup, do you have an example of the .babelrc or webpack-config.js changes I should make for it to be up and running? Thanks in advance, great post!
Hey! I know it's been a while but you can find a TypeScript example here
I have followed the entire article as it is. But i am getting the below mentioned error. Does anyone know how to fix it?
django-react-starter\frontend\templates\frontend\index.html, error at line 11
Exception Value:
expected string or bytes-like object
8
9
10
11 ... render_bundle 'frontend' ..
12
13
UPDATE: I did end up solving this, but I'm leaving my original message up. See below for the fix.
Hey @samar08 I'm receiving the same error. I've been trying to find a solution for a couple of days now and I'm coming up empty. I wasn't sure if it was a version thing or not. I'm using Python 3.9 and Django 4, but I tried Django 3 and had the same error. Are you using Python 3.9 or a different version? The babel and webpack versions I'm using seem to be releases from 2021 or earlier, so I don't think it's that. Have you solved it yet?
EDIT: I solved it! I had a newer version of webpack that was causing the issue. Python 3.9 and Django 4 seem to work fine so far.
On 26th line of webpack.config.js redundant '},'
Good catch. Fixed!
Thanks for the great post. I was wondering if you can achieve the same thing with
create-react-app
so that you don't have to do the webpack and babel setup?yeah, I am interested in knowing the same. Why is this article so complex when compared with this one. Essentially both try to achieve the same thing and atleast the latter one is tested by me and is a simpler approach