Closed smcalilly closed 1 year ago
Ok, we had this same issue with chi-land-sales
, and we fixed it by adding the --global
flag to the babelify subcommand, so our commands looked like this:
COMPRESS_PRECOMPILERS = (
(
"module",
"export NODE_PATH=/app/node_modules && npx browserify {infile} -t [ babelify --global --presets [ @babel/preset-env ] ] > {outfile}",
),
(
"text/jsx",
"export NODE_PATH=/app/node_modules && npx browserify {infile} -t [ babelify --global --presets [ @babel/preset-env @babel/preset-react ] ] > {outfile}",
),
)
@hancush did y'all have the problem with react or vanilla js? i tried the global flag in both the il-nwss-dashboard repo and the fresh repo from the cookiecutter, but still had the same problem. il nwss code for reference
@smcalilly React
good info! weird that it would work for react but not vanilla js.
this gave me a hunch. i removed the browserify-css
from the command chain and it fixed the vanilla js... so much for all that work to figure out #236
Related to #291
this should no longer be an issue once we incorporate webpack.
Description
Django compressor fails when trying to compile HTML which sources a vanilla JS file that imports a local JS module. (IDK how to write that rn out without breaking a brain, so see code example in the
Create a new app with the Django cookiecutter
section.)I recieved variations of this error:
And:
They all had the
'import' and 'export' may appear only with 'sourceType: module'
. There's a lot going on here and I'm not sure which part is broken. There's Django compressor, babelify, browserify, and JavaScript modules. I attempted to fix this with babelify configuration but I've spent too much time debugging this and need to pickup the issue with R&D now that I have a working but not ideal solution.This happened in a few of different places.
Steps to reproduce
1. Create a new app with the Django cookiecutter
It should have two files like this:
helloworld.js
base.js
helloworld.js
is imported intobase.js
.base.js
is used in the HTML like this:2. Setup offline compression
Turn on Django offline compression. Here's an example: https://github.com/datamade/ucb-cales/commit/2861a38272f70e7b33d482ae321020cc7a6d841c
Try to build the app. You should get this error: