reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

Fix unsafe of "this" inside module initialization (TypeError: Cannot use 'in' operator to search for 'window' in undefined)

Open AlonMiz opened this issue 3 years ago • 3 comments

when using esbuild with vite. this file generates an exception.

TypeError: Cannot use 'in' operator to search for 'window' in undefined
    at reqwest.js:15
    at reqwest.js:8
    at ../node_modules/reqwest/reqwest.js (reqwest.js:10)
    at __require2 (chunk-RDZ5XA5N.js?v=dde87764:17)
    at ../node_modules/auth0-js/index.js (index.js:14)
    at __require2 (chunk-RDZ5XA5N.js?v=dde87764:17)
    at dep:auth0-js:1

this is how it looks like when compiled with esbuild+vite. "this" is now referencing a different context than the intended window. image

using global this will make it more robust. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis

AlonMiz avatar Jun 12 '21 20:06 AlonMiz

I got the same problem, seems the author is not maintaining...

AnsonKong avatar May 08 '24 06:05 AnsonKong

you can try use the forked version we've published few years ago https://www.npmjs.com/package/reqwest-logz

AlonMiz avatar May 08 '24 08:05 AlonMiz

you can try use the forked version we've published few years ago https://www.npmjs.com/package/reqwest-logz

it works! thanks!

AnsonKong avatar May 08 '24 08:05 AnsonKong