Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Error message in expo-service-worker.js on project start #1138

Closed
alaindresse opened this issue Oct 20, 2019 · 2 comments
Closed

Error message in expo-service-worker.js on project start #1138

alaindresse opened this issue Oct 20, 2019 · 2 comments
Assignees
Labels
outdated Platform: web Using Expo in the browser

Comments

@alaindresse
Copy link

alaindresse commented Oct 20, 2019

Description

expo-service-worker.js generates an error in the log when listening to message events because event.data is not necessarily of type string (I have 4 messages in which event.data is a json object, not a string).

Expected Behavior

I just launched a website created from an expo project, and the errors appeared. I don't know what sends these messages (but I suspect it is firebase related).

Observed Behavior

I get the following message in my console (4 displays of this error)

Uncaught SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse (<anonymous>)
    at expo-service-worker.js:8
(anonymous) @ expo-service-worker.js:8

Environment

Expo CLI 3.4.1 environment info:
    System:
      OS: macOS 10.14.6
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
      npm: 6.11.3 - ~/.nvm/versions/node/v10.16.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    IDEs:
      Android Studio: 3.5 AI-191.8026.42.35.5791312
      Xcode: 11.1/11A1027 - /usr/bin/xcodebuild
    npmPackages:
      @types/react: ^16.9.5 => 16.9.5 
      @types/react-native: ^0.57.65 => 0.57.65 
      expo: ^35.0.0 => 35.0.0 
      react: 16.8.3 => 16.8.3 
      react-native: https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz => 0.59.8 
    npmGlobalPackages:
      expo-cli: 3.4.1

Reproducible Demo

I'll try to create a project that illustrates the issue.

I believe the following should do it, but I'm a bit short on time (will try it tomorrow)

import * as React from 'react';
import { View,Button } from 'react-native';

export default class App extends React.Component {
  handlePress = ()=>{
     navigator.serviceWorker.controller.postMessage({content:"non text message"});
  }
  render() {
    return (
      <View>
          <Button onPress={this.handlePress} title="Send message"/>
      </View>
    );
  }
}
@alaindresse
Copy link
Author

A github public project illustrating the issue is available here: https://github.com/alaindresse/post-message-error.
To reproduce,

  • build the web project
    expo build:web
    
  • then serve the build folder
    serve web-build
    
  • click on the send message button
  • open the console to see the error message.

@EvanBacon EvanBacon self-assigned this Nov 4, 2019
@EvanBacon EvanBacon added the Platform: web Using Expo in the browser label Nov 4, 2019
@EvanBacon
Copy link
Contributor

EvanBacon commented Nov 15, 2019

fixed with #1154. Also thanks so much for the example, it was extremely helpful for debugging quickly.

@lock lock bot added the outdated label May 20, 2020
@lock lock bot locked and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated Platform: web Using Expo in the browser
Projects
None yet
Development

No branches or pull requests

2 participants