EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 446 forks source link

Cannot use import statement outside a module #1621

Closed butaminas closed 4 years ago

butaminas commented 4 years ago

Using nativescript-vue and can't make my app run after upgrading to latest version of nativescript.

"nativescript": {
  "id": "xxx",
  "tns-ios": {
    "version": "6.5.1"
  },
  "tns-android": {
    "version": "6.5.1"
  }
},

App.js:

import Vue from "nativescript-vue";
import App from "./components/App";

const firebase = require('nativescript-plugin-firebase')
const {LocalNotifications} = require("nativescript-local-notifications")

firebase.init({
    showNotifications: true,
    showNotificationsWhenInForeground: true,
    onMessageReceivedCallback: (message) => {
        console.log('[Firebase] onMessageReceivedCallback:', {message});
        LocalNotifications.schedule(
            [{
                id: 1,
                title: message.data.title,
                body: message.data.body,
                silhouetteIcon: 'res://ic_app_icon',
                thumbnail: "res://icon",
                forceShowWhenInForeground: true,
                notificationLed: true,
                channel: i18n.t('messages_about_orders')
            }])
            .catch(error => console.log("doSchedule error: " + error));
    }
}).then(
    function () {
        console.log("firebase.init done");
    },
    function (error) {
        console.log("firebase.init error: " + error);
    }
);

I run tns run android and right after I get Webpack build done in the console I get these messages and a crash:

nativescript-plugin-firebase: /Users/butaminas/Local Sites/getfast.co.nz-courier-app/platforms/android/.pluginfirebaseinfo not found, forcing prepare!
nativescript-plugin-firebase: running release build or change in environment detected, forcing prepare!
Cannot use import statement outside a module
EddyVerbruggen commented 4 years ago

If you comment the Firebase stuff, does it then still crash with the same error?

butaminas commented 4 years ago

I can comment out my app.js completely I still get the same result.
I don't know why but even if I remove the plugin using npm remove nativescript-plugin-firebase or / and tns plugin remove nativescript-plugin-firebase

I still get the same error.

butaminas commented 4 years ago

I figured it out. It was the problem with hooks folder in the project root directory.

I don't know why this happened but after removing the plugin (the hooks directory was not removed) I removed the hooks folder manually and then installed the plugin again - the problem disappeared.

I don't know if this is a bug or not. Perhaps the hooks folder should be handled accordingly be the plugin to avoid this?