shadow-cljs 2025-05-28

I am running into another fun issue with a package: @lezer/php:

Closure compilation failed with 1 errors
--- node_modules/@lezer/php/dist/index.cjs:49
Illegal redeclared variable: global
This is happening with the following package: https://github.com/lezer-parser/php This is a dependency of something we are forced to use unfortunately. I did notice they also have a es module (not sure if that fixes things). I am using the following settings
:target :esm
:runtime :browser

shadow-cljs (and as far I know know ever JS tool in this world) wraps the commonjs code in a function with this signature function(global,require,module,exports) (the signature may vary between tools)

hence global is defined this way and the code is trying to do const global = ...

which the closure compiler is picky about, but I guess no alone in based on this issue

That maintainer is pretty annoying about it

you could try the esm files I guess. they are handled differently and don't have this implicit global

I tried they also fail

It seems the commonjs files work the best most of the time anyway. Have now put the resolution of false since we don't use that part

ah no nevermind that also has the global

I suppose I could just omit the global name if the source doesn't use global

but given that this file does use global it would need to be smart enough to detect that it is actually declaring global, not just using it

possible but not trivial

I don't think you should fix it honestly

We have 1000's of packages and this is the only one with this issue

to be fair I always considered this wrapper a bit hacky

webpack also uses a wrapper, but renames the variables, I guess to prevent exactly this

fixed it 😉

actually already had most of the code in place anyway

Oh haha 😆 nice!

should be fine as of 3.1.5

🙏 1
🚀 1

And it works!