Flutter web app & firebase : Cannot use import statement outside a module

Viewed 323

I want to connect firebase to my flutter web app. I followed all solutions on web, official and advice.

my flutter version : Flutter 2.6.0-12.0.pre.522

I have always this error inside console :

Uncaught SyntaxError: Cannot use import statement outside a module

the code inside index.html from build/web : (my firebase version : 9.21.0)

<body>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-storage.js"></script>
<script>
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
const firebaseConfig = {
   apiKey: "",
   authDomain: "",
   projectId: "",
   storageBucket: "",
   messagingSenderId: "",
   appId: ""
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
</script>

the main.dart

import 'package:firebase_core/firebase_core.dart';
Future<void> main() async {
   WidgetsFlutterBinding.ensureInitialized();
   await Firebase.initializeApp();
   runApp(MyApp());
}

the firebase folder have only an hosting.(numbers).cache

the firebase.json :

{"hosting": {
"public": "build/web",
"ignore": [
"firebase.json",
   "**/.*",
   "**/node_modules/**"
],
"rewrites": [
   {
      "source": "**",
      "destination": "/index.html"
   }
]
}
}

and my pub spec.yaml:

dependencies:
   flutter:
      sdk: flutter
   firebase_core: ^1.8.0
   firebase_auth: ^3.1.4
1 Answers
Related