My site has been working fine since I started using PostCSS with Hugo some 6 months ago. Today on starting the hugo server I got the following error message…
Building sites … /snap/hugo/8138/lib/node_modules/postcss-cli/node_modules/fs-extra/lib/mkdirs/make-dir.js:86
} catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/snap/hugo/8138/lib/node_modules/postcss-cli/node_modules/fs-extra/lib/mkdirs/index.js:3:44)
Strange that this has happened after upgrade to Hugo 70, although all is working well on a sister site I have with Hugo70/PostCSS. There has been no change to the postCSS config nor build commands.
I am not a node expert and am having trouble solving this and would like some assistance if anybody can shed some light on this. I suspect there is an easy answer but it is beyond me.
Please use the three backticks around code samples to make it easier to read. or use the </> button above the editor field.
Did you run npm update in your projects root directory after you updated Hugo? That would be my first step. The error is within PostCSS trying to create a directory or something like that. Might resolve itself if there are any updates in PostCSS.
Another “hacky” approach I would try is to delete the node_modules folder and then re-run npm install.
The problems I experienced around PostCSS in any of my projects were always related to some hanging versions. Maybe in package.json you have a fixed version number for postcss (if any) and that is not upgraded somehow. But more than that I can’t say without seeing the full repository to test here locally.
There is a relatively new bug open about postcss with fast rendering - not sure if that has anything to do with it. Are you building with fastRender as option?
I’ll have a look at your repo tomorrow. Quite late here now.
My test of installing from the Ubuntu repository was invalid. I’m running Ubuntu 20.04, so apt-get install hugo installed 0.68.3, not 0.70.0. See https://packages.ubuntu.com/search?keywords=hugo.
However, my test of building from source is still valid. I still believe this problem is limited to the snap package.
I’m running 20.04 too. Does sound like snap problem. Have reverted back to snap 0.69.2 to get something urgent done. Works fine. PostCSS/PurgeCSS working as normal.
If someone is asking herself how to revert back to hugo 0.69.2 using snap, here are the steps.
First we list the available revisions for the hugo package in snap:
$ snap list --all hugo
Name Version Rev Tracking Publisher Notes
hugo 0.69.2 8093 extended/stable hugo-authors disabled
hugo 0.70.0 8140 extended/stable hugo-authors -
Then, we revert the package to a previous revision, in our case 8093:
$ snap revert --revision=8093 hugo
hugo reverted to 0.69.2
Double-check if everything is in ordnung:
$ hugo version
Hugo Static Site Generator v0.69.2/extended linux/amd64 BuildDate: 2020-04-24T12:43:32Z
I played around and found only things, that are NOT the reason for the issue. Might be helpful for somebody who has to debug the underlying issue
it’s not about the output.css file (file size, syntax errors). that file is quite large and commented, but even with a single css line the error still comes up
it’s not an incompatibility with the local and hugos packages. I realized that postcss-cli was not used from your repo, but from within hugo. installing it local, install fs-extra local does not change the error (but uses the local packages)
it’s not a file rights issue
it’s not an issue with the syntax of the template file.
Comparing the releases there is no update to postcss itself, but a significant update from golibsass 0.5.0 to 0.6.0.
If I would know how my next step would be testing if reversing that single change is stopping the error.
I never had the need to postprocess already existing css. As your postcss processes don’t do anything other than minification and cleanup the following change in your footer template will do what’s needed and keep Hugo happy for now:
By the way: fingerprinting and THEN postprocessing (as done in the original footer template) will make the fingerprint invalid because the fingerprinted content of the file has changed while being post-processed.
If that is a theme you got from a developer (as in you did not create it by yourself) it’s time to open a bug about the postprocessing in the repo for the theme.
Thanks for the comments. The biggest job that postCSS does in this case is to purge all the unused css. The theme is built on Tailwind with it’s substantial size. Purgecss is necessary to bring the final file size down from 1.1mb to 20km. I will do some experimenting with the code as you suggest though and also some tidying up.
Reverting to the previous version of Hugo (69 via snap) does solve the problem in the short-term, but means I cannot update to 70 until this issue is resolved.
The theme is developed by myself, I am not a professional developer, just an enthusiastic amateur!