Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug/Question] how to use (with Angular) #13

Closed
daniel-sc opened this issue Feb 9, 2023 · 1 comment
Closed

[Bug/Question] how to use (with Angular) #13

daniel-sc opened this issue Feb 9, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@daniel-sc
Copy link

Describe the bug
I tried to add this to the Angular polyfills.ts (see https://angular.io/guide/browser-support#polyfills). I tried different setups:

import {installIntoGlobal} from 'iterator-helpers-polyfill';
installIntoGlobal();

and as well simply importing:

import 'iterator-helpers-polyfill';

In both cases it compiles with angular cli, and seems to be working correctly at runtime, but (at runtime/in the browser) I get the following error:

Uncaught TypeError: Object.defineProperty called on non-object
    at defineProperty (<anonymous>)
    at de (bundle.min.mjs:1:23388)
    at ve (bundle.min.mjs:1:23516)
    at 40497 (bundle.min.mjs:1:23679)
    at __webpack_require__ (bootstrap:19:1)
    at 77935 (polyfills.js:14:83)
    at __webpack_require__ (bootstrap:19:1)
    at __webpack_exec__ (wrapAsyncGenerator.js:6:1)
    at wrapAsyncGenerator.js:6:1
    at webpackJsonpCallback (jsonp chunk loading:71:1)

To Reproduce
Steps to reproduce the behavior:

  1. create new angular cli project: npx ng new
  2. npm i iterator-helpers-polyfill
  3. add import 'iterator-helpers-polyfill'; to polyfills.ts
  4. run ng serve
  5. Open http://localhost:4200 and observe the error in the console

Alternatively you can checkout https://github.com/daniel-sc/angular-reproduction-iterator-helpers-polyfill and run npm i && npm run start and observe the error on http://localhost:4200

Expected behavior
There should be no error.

Additional context
To get the types correctly for the IDE, one should add "node_modules/iterator-helpers-polyfill/declarations" to typeRoots in tsconfig.json.

@daniel-sc daniel-sc added the bug Something isn't working label Feb 9, 2023
@MadProbe
Copy link
Owner

MadProbe commented Feb 9, 2023

First:
I am honestly deeply impressed by the quality of this issue and I want to give immense respects and I absolutely love the work you have put into this issue. I am grateful to you again so much I can't even start to express how this is well done. Great job, my friend!

Second:
The main issue here arises from the fact that angular polyfills async generators and I can only prevent only this error from throwing by falling back to dynamically compiled function that in runtime would get the native async generator function and then the async generator prototype, but the fix is largely impossible without a good async generator polyfill that will make a prototype to async generators to which I could cling to (the main proposal is about adding methods to async iterators prototype, from which async generator's prototype inherits the methods) but the angular's polyfill doesn't give any to work with and I can only recommend you to tweak babel's configuration from polyfilling the async generator functions and I am sure that my polyfill will work properly.

P.S. The async generator functions polyfill that babel uses is able to only provide basic functions of async generators but currently it doesn't have any of the prototype chain stuff so maybe it is worth opening an issue on the polyfill's github page that babel uses. I am not sure but I think it's regenerator-runtime. Maybe it is not something that babel uses when native generator functions are available, so I advise you to walk through babel's dependency tree and find something linked to generators.

P.P.S. I should mention about this on project's page. I will make a commit to address this tomorrow.

Thank you very much,
Best regards.

@MadProbe MadProbe pinned this issue Feb 14, 2023
@MadProbe MadProbe closed this as not planned Won't fix, can't repro, duplicate, stale Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants