“无法编译react-native-push-notification”错误是什么意思?

时间:2019-10-10 21:55:20

标签: javascript reactjs react-native

React和React Native的新手-在安装react-native-push-notification(和@ react-native-community / push-notification-ios)并尝试使用它们后,我收到以下错误:

Failed to compile.

./node_modules/react-native-push-notification/index.js
Module parse failed: Unexpected token (32:40)
You may need an appropriate loader to handle this file type.
| };
| 
| Notifications.callNative = function(name: String, params: Array) {
|   if ( typeof this.handler[name] === 'function' ) {
|       if ( typeof params !== 'array' &&
^C

我有一个“ push.js”文件,该文件使用了以下依赖项:

//push.js

import PushNotification from 'react-native-push-notification';
import {
  PushNotificationIOS
} from 'react-native';

const configure = () => {
  PushNotification.configure({

    onRegister: function(token) {
      //process token
    },

    onNotification: function(notification) {
      // process the notification
      // required on iOS only
      notification.finish(PushNotificationIOS.FetchResult.NoData);
    },

    permissions: {
      alert: true,
      badge: true,
      sound: true
    },

    popInitialNotification: true,
    requestPermissions: true,

  });
};

const localNotification = () => {
  PushNotification.localNotification({
    autoCancel: true,
    largeIcon: "ic_launcher",
    smallIcon: "ic_notification",
    bigText: "My big text that will be shown when notification is expanded",
    subText: "This is a subText",
    color: "green",
    vibrate: true,
    vibration: 300,
    title: "Notification Title",
    message: "Notification Message",
    playSound: true,
    soundName: 'default',
    actions: '["Accept", "Reject"]',
  });
};


export {
  configure,
  localNotification
};

在“ App.js”中,我从“ push.js”中导入功能,如果我注释掉了导入,我将不再遇到编译问题:

//App.js

import React, {
  Component
} from "react";
import HomeScreen from "./HomeScreen";
//No compilation issue if I comment it out as shown below
//import * as PushNotifications from './services/PushNotifications';

//PushNotifications.configure();

class App extends Component {
  render() {
    return <HomeScreen />;
  }
}

export default App;

主要问题是我不知道此错误意味着什么,因此不确定从哪里开始进行故障排除.....

0 个答案:

没有答案