1

I've been trying to troubleshoot my project for the past day or so with no luck so far. Haven't documented the steps I've taken so far but will do my best to give an overview.

Yesterday my app was running fine, I went to open the remote debugger, the app crashed with an error. I assumed it was nothing and carried on debugging for a bit. Eventually I started getting the error.

window.addEventListener is not a function.
(In 'window.addEventListener("testPassive", null, e)', 'window.addEventListener' is undefined)

I did a quick google search here, here and found users linking the error when declaring firebase.initalizeApp(config). I followed some of the advice.

  • Downgrade/upgrade, remove, reinstall Firebase. npm install firebase/expo install firebase throws

        gyp ERR! build error
    
        gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
    
        gyp ERR! stack     at ChildProcess.onExit (C:\Users\user\Documents\React\project\node_modules\node-gyp\lib\build.js:194:23)
    
        gyp ERR! stack     at ChildProcess.emit (node:events:369:20)
    
        gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
    
        gyp ERR! System Windows_NT 10.0.19041
    
        gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\user\\Documents\\React\\project\\node_modules\\node-gyp\\bin\\node-gyp.js" "build" "--fallback-to-build" "--library=static_library" "--module=C:\\Users\\user\\Documents\\React\\project\\node_modules\\grpc\\src\\node\\extension_binary\\node-v88-win32-x64-unknown\\grpc_node.node" "--module_name=grpc_node" "--module_path=C:\\Users\\user\\Documents\\React\\project\\node_modules\\grpc\\src\\node\\extension_binary\\node-v88-win32-x64-unknown" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v88"
    
        gyp ERR! cwd C:\Users\user\Documents\React\project\node_modules\grpc
    
        gyp ERR! node-gyp -v v7.1.2
    
        gyp ERR! not ok
    
        node-pre-gyp ERR! build error
    
        act\project\node_modules\grpc\src\node\extension_binary\node-v88-win32-x64-unknown\grpc_node.node --module_name=grpc_node --module_path=C:\Users\user\Documents\React\project\node_modules\grpc\src\node\extension_binary\node-v88-win32-x64-unknown --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v88' (1)
    
        node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (C:\Users\user\Documents\React\project\node_modules\node-pre-gyp\lib\util\compile.js:83:29)
    
        node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:369:20)
    
        node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1067:16)
    
        node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
    
        node-pre-gyp ERR! System Windows_NT 10.0.19041
    
        node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\user\\Documents\\React\\project\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build" "--library=static_library"
    
        node-pre-gyp ERR! cwd C:\Users\user\Documents\React\project\node_modules\grpc
    
        node-pre-gyp ERR! node -v v15.12.0
    
        node-pre-gyp ERR! node-pre-gyp -v v0.14.0
    
        node-pre-gyp ERR! not ok```
    
    
  • Insert window.addEventListener = x => x; at the top level of your app.

  • Downgrade/upgrade Node.js

  • Create a new Expo project, copy over components and reinstall packages from scratch

  • clear npm cache, delete package-lock.json and run npm install

  • yarn add firebase gets struck on building fresh packages... grpc waiting... then after 5 mins or so throws:

       yarnpkg exited with non-zero code: 1
    
       Error: yarnpkg exited with non-zero code: 1
    
         at ChildProcess.completionListener (C:\Users\user\AppData\Roaming\npm\node_modules\expo-cli\node_modules\@expo\spawn-async\src\spawnAsync.ts:65:13)
    
         at Object.onceWrapper (node:events:476:26)
    
         at ChildProcess.emit (node:events:369:20)
    
         at ChildProcess.cp.emit (C:\Users\user\AppData\Roaming\npm\node_modules\expo-cli\node_modules\cross-spawn\lib\enoent.js:34:29)
    
         at maybeClose (node:internal/child_process:1067:16)
    
         at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
    
         ...
    
         at Object.spawnAsync [as default] (C:\Users\user\AppData\Roaming\npm\node_modules\expo-cli\node_modules\@expo\spawn-async\src\spawnAsync.ts:26:19)
    
         at YarnPackageManager._runAsync (C:\Users\user\AppData\Roaming\npm\node_modules\expo-cli\node_modules\@expo\package-manager\src\NodePackageManagers.ts:301:31)
    
         at YarnPackageManager.addAsync (C:\Users\user\AppData\Roaming\npm\node_modules\expo-cli\node_modules\@expo\package-manager\src\NodePackageManagers.ts:254:16)
    
         at installAsync (C:\Users\user\AppData\Roaming\npm\node_modules\expo-cli\src\commands\install.ts:130:3)
    
         at Command.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_modules\expo-cli\src\exp.ts:349:7)```
    
  • yarn add firebase also throws:

    warning firebase > @firebase/firestore > grpc > node-pre-gyp@0.14.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future

  • yarn add @mapbox/node-pre-gyp doesn't seem to make the warning go away and raises the same error

  • Disable firewall, run installs

  • Run installs with --force command/flag

Other projects seem to be booting fine. I have absolutely no clue what is going on here.

Yam N
  • 13
  • 3

1 Answers1

0

Insert window.addEventListener = x => x; at the top level of your app.

There is no global window.addEventListener function in React Native. The execution environment is different from a web browser.

(errors installing Firebase)

You can install firebase@8.2.3 - yarn add firebase@8.2.3 and I believe they've removed the grpc dependency in that version. Building native dependencies for Node packages commonly fails on Windows machines for a variety of reasons, you should search issues on repositories related to those packages for more information when you encounter in the future. eg: https://github.com/grpc/grpc-node/issues/1183

brentvatne
  • 7,603
  • 4
  • 38
  • 55