juanjoDiaz / json2csv

Flexible conversion between JSON and CSV
https://juanjodiaz.github.io/json2csv/
MIT License
296 stars 32 forks source link

Uncaught (in promise): TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'. #30

Closed rianluoar closed 1 year ago

rianluoar commented 1 year ago
  1. Using "@json2csv/whatwg": "^6.1.3".
  2. node version 18.16.0 or running on chrome 113.0.5672.93
  3. Using json in angular application https://github.com/rianluoar/angular16-json2csv clone the angular application and run npm i. After installing node module run command "npm start". Open http://localhost:4200/ on chrome and click on download button.
  4. After clicking on download button getting below error in console json2-csv.service.ts:12 ERROR Error: Uncaught (in promise): TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'. TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'. at <computed> [as dispatchEvent] (TransformStream.js:42:51) at JSON2CSVWHATWGTransformStream.transformer.onHeader (TransformStream.js:45:47) at Transformer.pushHeader (StreamParser.js:128:12) at Transformer.pushLine (StreamParser.js:146:12) at Object.write (StreamParser.js:29:29) at Transformer.transform (TransformStream.js:25:20) at resolvePromise (zone.js:1193:31) at zone.js:1100:17 at zone.js:1116:33 at asyncGeneratorStep (asyncToGenerator.js:6:1) at _throw (asyncToGenerator.js:25:1) at _ZoneDelegate.invoke (zone.js:368:26) at Object.onInvoke (core.mjs:26117:33) at _ZoneDelegate.invoke (zone.js:367:52) at Zone.run (zone.js:127:43) at zone.js:1257:36
  5. Please refer https://github.com/rianluoar/angular16-json2csv/blob/main/src/app/json2-csv.service.ts#L10 for code reference.
rianluoar commented 1 year ago

Just for testing purpose I removed (...args) from line 42 of TransformStream.js it started working as expected on my local system. @juanjoDiaz https://github.com/juanjoDiaz/json2csv/blob/main/packages/whatwg/src/TransformStream.js#L42

image

juanjoDiaz commented 1 year ago

Hi @rianluoar ,

Yes. This is a known issue. Fixed in the upcoming typescript version that I've been trying to release since forever. I'll try to get it out asap.

juanjoDiaz commented 1 year ago

I just released v7.0.0 which entirely rewrites @json2csv to typescript. This issue should be solved there.

Let me know if you find any other issues with it. This was a massive change.