Not all new JS dependencies are getting installed?

I’m working on a JavaScript website, and had it working for a few days. Until I added a new dependency today, and now I am getting JS errors in the console.

In my package.json, under dependencies, I added a new one:

"dompurify": "^2.0.8"

And then in my site’s code I use this new package:

import purify from "DOMPurify";
purify.sanitize(html);

Locally, everything works great. No errors while in dev mode, no errors when I create a production build either. But when I deploy my site to Netlify and it creates a build, I get an error saying ReferenceError: Can't find variable: purify when I open the site.

I tried to rebuild without cache, but that didn’t help. What else could it be?

hey there, good to see you again. this isn’t the first time dompurify has surfaced here lately.

maybe this is of interest to you:

I missed it in the logs at first, but upon closer inspection I do see the following:

6:11:13 PM: (!) Unresolved dependencies
6:11:13 PM: https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
6:11:13 PM: DOMPurify (imported by src/Characters/Details.svelte)
6:11:13 PM: (!) Missing global variable name
6:11:13 PM: Use output.globals to specify browser global variable names corresponding to external modules
6:11:13 PM: DOMPurify (guessing 'purify')

I’ll dig in. Not sure why it works locally, but :man_shrugging:

I had to change import purify from "DOMPurify"; to import purify from "dompurify";

D’oh! Weird that it worked totally finally without problem locally. Case-sensitive file system vs non-cs I guess?

1 Like

i bet that was it! glad its working now!