vauxite-org / typescript-logging

TypeScript Logging library for both TypeScript and JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React-native app crashes: "window.removeEventListener" is not a function

maudnals opened this issue · comments

We have a react native app, created with react-native init.
Importing typescript-logging makes the app crash.
This issue didn't come up in a project using react-native 0.59.

  • react-native version: 0.61.2.
  • typescript-logging version: 0.6.3

Steps to reproduce:

  • Create a new react native project with react-native init (see https://facebook.github.io/react-native/docs/getting-started > tab "React native")
  • Launch the app: yarn start in one terminal tab and react-native run-ios in another
  • Add "typescript-logging": "^0.6.3" into package.json and run yarn
  • Add import logger from 'typescript-logging' into App.js
  • The app crashes (see screenshot)

Thanks in advance for your help!! 🚀 @mreuvers

Screenshot 2019-10-11 at 11 17 12

Hello @maudnals ,

Thank you for reporting the issue. My guess is that you used to have something in your project that poly-filled various methods (such as the one now failing on the window object). Maybe due to the upgrade of react-native, or something else you upgraded/dropped in your project?

In any case where it currently fails is not even relevant for a native app (it's related to the extensionpoint for chrome and you can't use that anyway).

I intend to fix this, would you be willing to test this later once fixed on a branch? I am unable to test it myself as I run linux and can't test on ios.

Hello @mreuvers,

Thank you for your swift reply.
Happy to test the fix later on!

I've set up an example app where the issue happens, so you can see my exact setup if that helps: https://github.com/maudnals/react-native-logger-test/tree/master

This example app has been created following the steps mentioned above (#43 (comment)): simply create a react native app and add typescript-logging as a dependency. So I'm not sure that this may relate to a manual react upgrade or polyfill (if I got you right).

Let me know if I can help in any way!

Probably not then, unless they shipped a poly-fill previously in an older version?
In any case, let's try fix it. :)

I will let you know when a branch with hopefully the fix is available for you to test (it may be a few days). Thank you!

Sure, thanks!

Hello @maudnals,

I have made the fix and hopefully it will work.

To test (yarn command should be similar I think?):

  • clone this repository
  • in the clone directory:
    • git checkout issue43
    • npm ci (this one matters, it installs the dependencies from package-lock.json)
    • npm run release (builds & tests)
    • npm pack (this will create a 0.6.4 tgz file)
  • in your test project directory:
    • npm uninstall typescript-logging --save
    • check that it was removed: node_modules/typescript-logging (should be gone)
    • npm install path_to_0.6.4.tgz
    • do your usual build and run the test project and hopefully it works again

Let me know how things go and/or if you have questions. Thanks!

Hi @mreuvers ,

Looking great! I've followed all the above steps and the app is running smoothly.
Thanks a ton for this fast fix 🎉

I see the additional checks you've added on there. Out of curiosity, do you know where the problem originated from? Has React changed the way window polyfills are applied in the latest react-native?

Hey @maudnals,

Glad to hear it works! :)

As for what changed, I don't know but apparently those functions were not present anymore - maybe they were poly-filled in your real project by react-native or even by some other library (don't know if you upgraded various items or threw things out).

In any case based on the react-native code it seems they register window = global (where global is react-native thingy), but do not define any window functions aside alert or so (for what I could find quickly in the code).

I hope to make an official release of this tomorrow or Friday.

Hello @maudnals,

I have merged everything back to master and also just published 0.6.4 to npm (for me it still shows 0.6.3, but that seems to be cache so may be some time before it's visible).

However you should be able to already use the 0.6.4 in your package.json. Can you please confirm 0.6.4 works when using the npm version (make sure to drop typescript-logging first to be sure you load the one from npm).

Thank you!

Hi @mreuvers,
Great, I've tested it, 0.6.4 in package.json works. Thanks!
From my perspective this issue can be closed - I leave it up to you.
Cheers!

Hey @maudnals,

Sounds like things are fine now, I will close this issue. Thanks again for reporting and testing it out!