React Native (Expo) 项目引发“window.addEventListener 不是函数”

任恩

过去一天左右,我一直在尝试对我的项目进行故障排除,但到目前为止没有运气。尚未记录我迄今为止采取的步骤,但会尽力提供概述。

昨天我的应用程序运行良好,我去打开远程调试器,应用程序因错误而崩溃。我认为这没什么,并进行了一段时间的调试。最终我开始收到错误。

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

我在这里做了一个快速的谷歌搜索在这里发现用户在声明firebase.initalizeApp(config). 我遵循了一些建议。

  • 降级/升级、移除、重新安装 Firebase。npm install firebase/expo install firebase抛出

        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```
    
    
  • window.addEventListener = x => x;在应用程序的顶层插入

  • 降级/升级 Node.js

  • 创建一个新的 Expo 项目,复制组件并从头开始重新安装包

  • 清除 npm 缓存,删除 package-lock.json 并运行 npm install

  • yarn add firebasebuilding fresh packages... grpc waiting...在 5 分钟左右的投掷后被击中

       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 还抛出:

    warning firebase > @firebase/firestore > grpc > [email protected]: 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 似乎没有使警告消失并引发相同的错误

  • 禁用防火墙,运行安装

  • 使用--force命令/标志运行安装

其他项目似乎启动良好。我完全不知道这里发生了什么。

布伦特瓦特

插入 window.addEventListener = x => x; 在您的应用程序的顶层。

window.addEventListenerReact Native 中没有全局函数。执行环境不同于网络浏览器。

(安装 Firebase 时出错)

您可以安装[email protected]-yarn add [email protected]我相信他们已经删除了该版本中的 grpc 依赖项。由于各种原因,在 Windows 机器上为 Node 包构建本机依赖项通常会失败,您应该在与这些包相关的存储库中搜索问题,以获取将来遇到的更多信息。例如:https : //github.com/grpc/grpc-node/issues/1183

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章