Expo通知无法调用`getExpoPushTokenAsync()`。

huangapple go评论76阅读模式
英文:

Expo notifications can't call `getExpoPushTokenAsync()`

问题

我目前正在尝试在我的托管 Expo 项目上设置通知。

  • Expo 版本 47.0.0
  • Expo 通知版本 0.17.0
  • 设备:三星 Galaxy S10
  • Android 版本 12

我目前只是试图让基本设置本身能够工作,并获取我的设备推送令牌。这应该使用 Notifications.getExpoPushTokenAsync() 来完成,如 这里 所描述。

问题

我的错误很奇怪,当我调用 getExpoPushTokenAsync 时,它确实获取了 Expo 推送令牌,但不久后我的应用程序崩溃,并显示以下消息:

ERROR  TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[1], "../../../src/util").types.isPromise')
 WARN  [expo-notifications] Error encountered while updating server registration with latest device push token. [TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "@ide/backoff").computeNextBackoffInterval')]

我尝试过以下方法:

  • 重新安装 node_modulesexpo-notifications,但仍然遇到相同的问题。
  • 我确实可以看到 @ide/backoff 包已安装在我的 node_modules 中。
  • 我还按照 这些说明 在应用程序中设置了 Firebase,尽管我理解在 Expo Go 应用程序中进行开发时它应该可以开箱即用。

另一个有趣的事情是,我可以调用 Notifications.getDevicePushTokenAsync(),没有错误。但是,如果我在之后将它传递给 getExpoPushTokenAsync 方法,仍然会出现相同的错误。表面上看,似乎请求到 Expo 服务获取 Expo 推送令牌既成功又失败 🤷‍♂️

const devicePushTokenResponse = await Notifications.getDevicePushTokenAsync();
const expoPushTokenResponse = await Notifications.getExpoPushTokenAsync({
  devicePushToken: devicePushTokenResponse,
}); // <--- 返回令牌并在几秒后出现错误

无法找到任何其他关于此错误和 expo-notifications 的帖子,所以我很愿意看看是否有其他人最近遇到或解决了类似的问题。

致敬

英文:

Am currently trying to setup notifications on my managed expo project

  • Expo version 47.0.0
  • Expo notifications version 0.17.0
  • Device: Samsung Galaxy s10
  • Android version 12

I am currently just trying to get the basic setup itself working and retrieve my devices push token. This should be done using Notifications.getExpoPushTokenAsync() as described here.

The Problem

My error is strange, when I call getExpoPushTokenAsync it does indeed get me the expo push token, however shortly after my app crashes with the following messages

ERROR  TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[1], "../../../src/util").types.isPromise')
 WARN  [expo-notifications] Error encountered while updating server registration with latest device push token. [TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "@ide/backoff").computeNextBackoffInterval')]

I have tried

  • re-installing node_modules and expo-notifications but still get the same.
  • I can definitely see the @ide/backoff package is installed in my node_modules.
  • I also followed these instructions to setup firebase in app, even though my understanding is that it should work out of the box in expo go app while devving.

One other interesting thing is that I can call Notifications.getDevicePushTokenAsync() fine with no error. But still get the same error if i pass that in to getExpoPushTokenAsync method after. At a surface level it seems like somehow the request out to expo services to get the expo push token is both passing and failing 🤷‍♂️

const devicePushTokenResponse = await Notifications.getDevicePushTokenAsync();
const expoPushTokenResponse = await Notifications.getExpoPushTokenAsync({
  devicePushToken: devicePushTokenResponse,
}); // <--- Returns token & errors a few seconds later

Couldn't see any other posts with this error and expo-notifications, so would be keen to see if anyone else has ran into / fixed a similar issue recently

Cheers

答案1

得分: 0

好的,这是翻译后的内容:

我明白了,这在这行代码中有一些暗示:
ERROR TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[1], "../../../src/util").types.isPromise')
更具体地说,一个node_modules的依赖项在文件系统中引用了3层上级。

解决方案

事实证明,出现这个问题的原因是我的模块解析器(在babel.config.js中定义)解析了我的项目的util文件夹,而不是包的util文件夹。我认为这可能是由于我的metro配置使用了inlineRequires功能来提高性能(查看更多)。

我确信有一些实际的配置可以更新,以排除node_modules不使用内联要求(我尝试过使用一个黑名单,但没有成功),但作为一个临时解决方案,我成功地通过将我的util文件夹的路径更改为@my-project/util来使其正常工作,以避免将来的冲突。

希望这能帮助将来遇到同样问题的人们:)

英文:

Alright I figured it out, it was somewhat hinted at by this line
ERROR TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[1], "../../../src/util").types.isPromise')

And more specifically the fact that a node_modules dependency is referencing 3 levels up in the file system.

The solution

Turns out that for some reason my module resolver (defined in babel.config.js) was resolving my project's util folder instead of the packages util folder. I think this was compounded by my metro config making use of the inlineRequires functionality to improve performance (see more)

I am sure there is some actual config that could be updated to exclude node_modules from using inline requires (i did try use a blocklist to no avail), but as an interim, i was able to get it working fine by changing the path of my util folder to be @my-project/util so that it avoids future collisions.

Hope this helps anyone who runs into the same issue in the future Expo通知无法调用`getExpoPushTokenAsync()`。

huangapple
  • 本文由 发表于 2023年1月9日 12:52:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75053305.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定