ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.56k stars 1.33k forks source link

Require is not defined on vanilla js #1743

Closed ing-fcastellanos closed 1 year ago

ing-fcastellanos commented 1 year ago

Hi! I'm getting an error while loading the latest version from the vanilla js browser script (https://cdn.jsdelivr.net/npm/superagent):

version: 8.0.1 browser: Edge 105.0.1343.53, Chromium 105.0.5195.125 Console output:

Uncaught ReferenceError: require is not defined
    at superagent:1:14164
    at superagent:1:269
    at superagent:1:274
lcoffin commented 1 year ago

Same here. Using either the jsdelivr.net or unpkg.com URLs. No code change on our end recently.

Browser: Firefox 105.0.1 Same error message as reported above.

lcoffin commented 1 year ago

Note you can get around this by specifically requesting v8.0.0 using:

titanism commented 1 year ago

Still determining the root cause of this

titanism commented 1 year ago

v8.0.2 released - can you please test? @fcastellanosKreios @lcoffin

https://github.com/visionmedia/superagent/releases/tag/v8.0.2

lcoffin commented 1 year ago

I'm still seeing the error with either of these URLs:

https://cdn.jsdelivr.net/npm/superagent https://cdn.jsdelivr.net/npm/superagent@8.0.2

@8.0.0 works fine still.

lcoffin commented 1 year ago

Note that I see this bit of code in 8.0.1 and 8.0.2 that I don't see in 8.0.0:

return"function"==typeof r&&W(t,".prototype.")>-1?_(r):r},V=require(12),Q=q("%TypeError%"),X=q("%WeakMap%",!0)

That's the only reference to require() anywhere in the code that I get.

titanism commented 1 year ago

It must be something to do with babel or .dist.babelrc?

titanism commented 1 year ago

tinyify v3.0.0 to v3.1.0 was changed here https://github.com/visionmedia/superagent/commit/1fc968219ee67a86f2e84c9ddcf5df9aa01780d0#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L69-R68 which could be the culprit - the minor version change was common-shakeify bumping major versions here https://github.com/browserify/tinyify/commit/1b0c002b2372270e76ceec2898e2b9816d5716ca

Though this doesn't seem like it'd be the issue

titanism commented 1 year ago

Deprecated v8.0.1 and v8.0.2 in the interim - help would be appreciated in determining the underlying cause here. It has to do with creating the dist/superagent.min.js file.

levino commented 1 year ago

Please release v8.0.0 as v8.0.3. Less inconvenient for the users,

lorand-horvath commented 1 year ago

@titanism Have you managed to find the underlying issue? Asking because npm install superagent still installs version 8.0.2 (even if it's deprecated) and not 8.0.0. Some kind of solution/fix would be very much appreciated until this problem is solved (perhaps releasing a temporary version 8.0.3).

lorand-horvath commented 1 year ago

@titanism After some investigation regarding tinyify and common-shakeify (you mentioned them above), it seems that 5 days ago there were version bumps for both of them: tinyify from 3.1.0 to 4.0.0 https://github.com/browserify/tinyify/releases/tag/v4.0.0 common-shakeify from 1.1.1 to 1.1.2 https://github.com/browserify/common-shakeify/releases/tag/v1.1.2

It looks like the latter has some related fixes to exports and invalid syntax, which might be the culprit and the fix: Fix certain cases of exports in sequential expressions resulting in invalid syntax https://github.com/browserify/common-shakeify/pull/43

Can you please check and see if updating to tinyify 4.0.0 and/or common-shakeify 1.1.2 would result in a correct build of superagent.min.js ?

titanism commented 1 year ago

v8.0.3 released to npm 🎉 !!

the issue was tinyify, which bumped common-shakeify, and has a few underlying issues that need resolved before we can upgrade it. apologies for the delay, this wasn't easy to track down.

https://github.com/visionmedia/superagent/releases/tag/v8.0.3