zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.73k stars 2.05k forks source link

Attempted import error: 'react-native-push-notification' does not contain a default export #1790

Open jan-ambroz opened 3 years ago

jan-ambroz commented 3 years ago

Bug

Trying to import PushNotifications but always getting error about missing default export.

Code:

import PushNotification from 'react-native-push-notification';
import NotificationHandler from './NotificationHandler';

export default class NotificationService {
    constructor(onRegister, onNotification) {
        this.lastId = 0;
        this.lastChannelCounter = 0;

        this.createDefaultChannels();

        NotificationHandler.attachRegister(onRegister);
        NotificationHandler.attachNotification(onNotification);

        // Clear badge number at start
        PushNotification.getApplicationIconBadgeNumber(function (number) {
            if (number > 0) {
                PushNotification.setApplicationIconBadgeNumber(0);
            }
        });........

error Attempted import error: 'react-native-push-notification' does not contain a default export (imported as 'PushNotification').

Dallas62 commented 3 years ago

Hi @johnW6

What's your library version, I'm not able to reproduce.

Regards,

jan-ambroz commented 3 years ago

HI @Dallas62 ,

I am using "^6.1.3"

Dallas62 commented 3 years ago

Hum, this is really strange, you are the first one which is opening this kind of issue.

Did you try to reinstall dependencies ?

jan-ambroz commented 3 years ago

I did now, yarn remove, yarn add and I am still getting:

/home/jan/code/my-project/NotificationService.js Attempted import error: 'react-native-push-notification' does not contain a default export (imported as 'PushNotification').

and my all dependencies:

`"dependencies": {
    "expo": "~40.0.0",
    "expo-splash-screen": "~0.8.0",
    "expo-status-bar": "~1.0.3",
    "expo-updates": "~0.4.0",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "~0.63.4",
    "react-native-gesture-handler": "~1.8.0",
    "react-native-push-notification": "^7.0.0",
    "react-native-reanimated": "~1.13.0",
    "react-native-screens": "~2.15.0",
    "react-native-unimodules": "~0.12.0",
    "react-native-web": "~0.13.12"
  },`
jan-ambroz commented 3 years ago

When I try to run it in browser i am getting:

TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
Module.<anonymous>
node_modules/react-native-push-notification/index.js:609
  606 |   return this.callNative('setNotificationCategories', arguments);
  607 | }
  608 | 
> 609 | module.exports = Notifications;
  610 | 
Dallas62 commented 3 years ago

Which platform are you using ? This library is made for iOS and Android, not web.

jan-ambroz commented 3 years ago

Yeah I am trying to run it in Android. There I have still error about import.

Dallas62 commented 3 years ago

This seems to be an issue with your metro bundler / compiler

drevera commented 3 years ago

hey @jan-ambroz I had the same error, did you find solution for that?

jan-ambroz commented 3 years ago

hey @jan-ambroz I had the same error, did you find solution for that?

no, i just switch to Flutter.