Exponent-server-sdk-node on AWS lambda

#1

Hi, thanks for the great platform. I have found one issue though with the referenced sdk for push notifications.

It seems the sdk does not work with node 6.10.3 which is the highest version currently supported on AWS lambda.

The below snippet illustrates the error:

const Expo = require('expo-server-sdk')

const expo = new Expo()

const postNotifications = (data, tokens) => {
  const messages = tokens.map(token => {
    return {
      to: token,
      sound: 'default',
      body: 'Message Test',
      data,
    }
  })

  return Promise.all(
    expo.chunkPushNotifications(messages).map(expo.sendPushNotificationsAsync)
  )
}

postNotifications({ some: 'data' }, [
  'ExponentPushToken[c0yskcIP2aPWwg4YMjcLCz]',
])
  .then(() => console.log('success!'))
  .catch(err => console.log('ERR', err))

If I run this with node index.js I get:

ERR TypeError: Cannot read property '_requestAsync' of undefined
    at _callee2$ (D:\dev\daily-office\service\node_modules\expo-server-sdk\build\ExpoClient.js:132:28)
    at tryCatch (D:\dev\daily-office\service\node_modules\regenerator-runtime\runtime.js:62:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (D:\dev\daily-office\service\node_modules\regenerator-runtime\runtime.js:296:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (D:\dev\daily-office\service\node_modules\regenerator-runtime\runtime.js:114:21)
    at step (D:\dev\daily-office\service\node_modules\babel-runtime\helpers\asyncToGenerator.js:17:30)
    at D:\dev\daily-office\service\node_modules\babel-runtime\helpers\asyncToGenerator.js:35:14
    at Promise.F (D:\dev\daily-office\service\node_modules\core-js\library\modules\_export.js:35:28)
    at D:\dev\daily-office\service\node_modules\babel-runtime\helpers\asyncToGenerator.js:14:12
    at sendPushNotificationsAsync (D:\dev\daily-office\service\node_modules\expo-server-sdk\build\ExpoClient.js:165:22)
    at Array.map (native)

I’m not too familiar with babel, but I’m assuming it is some issue with transpiling the newer syntax. Would it be possible for a maintainer to quickly take a look and see about fixing this?

If you have any pointers for getting this working on node 6.10 that would be great!

#2

@ide - any ideas here?

#3

This looks buggy:

expo.chunkPushNotifications(messages).map(expo.sendPushNotificationsAsync)

You need to make sure expo is bound in the mapper.

#4

Yep, you’re right. Classic case of over complicating the first implementation. Doing expo.chunkPushNotifications(messages).map(expo.sendPushNotificationsAsync, expo) worked. Sorry about that!

closed #5

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.