Closed David-Rickard closed 2 years ago
Thanks for reporting this. I'm on vacation right now, I will have a look next week or so.
I looked into this a little bit today and I think you should use another package. The "abortcontroller-polyfill" package was intended to add an AbortController to legacy browsers and it hasn't been tested in an nextjs environment. If you really want to add such support and do all the required testing etc I can merge it, given that it doesn't break any of the legacy browser support (in particular Safari 11.1.2 etc where there is a buggy AbortController available in the browser).
I recommend that you google a bit for another solution, maybe try this: https://github.com/vercel/next.js/discussions/32736 ... or talk to other people in the nextjs ecosystem to figure out how they usually solve this.
I'm not using it directly; it's coming in via a dependency in another package I'm using, one that tries to work in all environments. I've talked with them about it and the current plan is to remove the polyfill from it.
Just out of curiousity, which packages are you talking about here?
It's a shared package internal to DoorDash.
Repro steps: 1) Create a NextJS app with
pnpm create next-app --ts
2) Create amiddleware.ts
withimport 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
3) Runpnpm i
andpnpm dev
4) Go to http://localhost:3000/Expected result: App runs
Actual result: TypeError: Cannot redefine property: AbortController
It detects the environment as needing a polyfill via this line. The
fetch
property is missing, but it is unable to redefine the AbortController` property on the global object.https://github.com/David-Rickard/abortcontroller-polyfill-nextjs-repro