JS Build Error on Build - node modules not found

After getting the most recent upgrade, am encountering this error:

ERROR JSBUILD: failed to transform "/js/main.js" (text/javascript): Could not resolve "@cloudinary/url-gen" Built in 1557 ms Error: error building site: JSBUILD: failed to transform "/js/main.js" (text/javascript): Could not resolve "@cloudinary/url-gen"

So in my triaging this issue, if I disable the offending node_module, (@cloudinary/url-gen), Hugo will continue to build etc. So it seems like a matter of the module not being found, but therein lies the rub, as it were. If I nuke the entire node_modules folder and then run npm i again; no joy. I thought maybe it had something to do w/ the cloudinary module, so I tried a different module from npm just to see, and got the same build error.

I should add this was working on the previous version of Hugo. If I write JS with no module imports from the node_modules the project will build and everything works as expected…

So it seems that for some reason js.Build is not able to find the node modules directory. See below for my file structure:

├─ archetypes
├─ content
├─ data
├─ layouts
├─ node_modules
       ├─ @cloudinary
├── public
├── resources
├── sandbox
├── static
└── themes
          └─ blank
                 ├─ archetypes
                 ├─ assets
                 ├── js
                 ├─ ...

Node Version: 16.14.2
hugo v0.128.0+extended darwin/amd64 BuildDate=2024-06-25T16:15:48Z VendorInfo=brew

Not sure where to go from here, perhaps a config file is order, to explicitly direct js.Build to node modules?


Without seeing/trying the source, I don’t think it’s possible to guess what your problem may be.

@bep, roger that, here’s the repo / branch I’m working on. Dont judge me too harshly. :rofl:

As, always I am grateful for any insight and assistance!

So, it builds fine on my MacBook:

hugo v0.129.0-DEV-932ab4c058bf7a36e55d0f607b5a237f90a25405+extended darwin/arm64 BuildDate=2024-06-27T21:35:56Z

I did a fresh clone and then

npm i
hugo server

Checked the site and it seems to be working fine.

So, this is why I’m not a big fan of the NPM eco system and try to avoid it when I can. I have had NPM projects that stopped working for no obvious reason myself.

Are you sure that downgrading Hugo makes this somehow work for you?

Ah. I wasnt aware I was behind a version of gohugo. Brew has been giving me hard time lately, I’ll spare you the details, but when I run brew upgrade hugo its yelling back: Warning: hugo 0.128.0 already installed

I’ll dig into why Brew is not installing the latest… Could be OS related, not sure. I’m traveling atm and am not working on my primary computer.

Thank you much sir!

oh well, v0.128.0 is the latest. It shows v0129.0-DEV above because I build from source, but it’s the v0.128.0 source …

Well, some kind of very bespoke issue on my end (I’m looking at you Node!)
Not sure how to close this without “solving”…
regardless. thanks!

Just leave it open … Maybe others can chime in with some “I experienced the same thing and what I did was …”

1 Like