I want to import the firebase-database using esm import. I can only find the script version:
<script src="https://www.gstatic.com/firebasejs/7.21.0/firebase-database.js"></script>
What is the url I need for the esm module version?
Note: I do not want a "bare import", I am not using webpack etc. I need a complete url.
There is an older version available on unpkg.com but not the current version.
It turns out there are two CDN's that can provide this: snowpack/skypack, and jspm:
skypack:
import firebase from 'https://cdn.skypack.dev/#firebase/app'
import 'https://cdn.skypack.dev/#firebase/database'
jspm:
import { firebase } from 'https://jspm.dev/#firebase/app'
import 'https://jspm.dev/#firebase/database'
These both deal with "bare import" conversion to JS, and any code conversions required to be JS Modules.
Google does not appear to want to support a module form on their firebase CDN, an Issue to that effect was immediately closed, suggesting complex workflow solutions.
I'm really thankful to the two projects above, supporting simple es6 JS and zero workflow solutions.
Edit: snowpack's esinstall can turn most js files into modules. Here's a node script that brought in all my dependencies:
#!/usr/bin/env node --require esm
import { install } from 'esinstall'
import nodePolyfills from 'rollup-plugin-node-polyfills'
async function run() {
const foo = await install(
[
'mapbox-gl',
'three',
'three/examples/jsm/controls/OrbitControls.js',
'three/src/core/Object3D.js',
'chart.js',
'dat.gui',
'fflate',
'#turf/turf',
'stats.js',
'#firebase/app',
'#firebase/database',
],
{
rollup: {
plugins: [nodePolyfills()],
},
}
)
}
run()
If you're using a bundler, then follow the instructions in the documentation:
Install the firebase npm package and save it to your package.json file
by running:
npm install --save firebase
To include only specific Firebase products (like Authentication and
Cloud Firestore), import Firebase modules:
// Firebase App (the core Firebase SDK) is always required and must be listed first
import * as firebase from "firebase/app";
// If you enabled Analytics in your project, add the Firebase SDK for Analytics
import "firebase/analytics";
// Add the Firebase products that you want to use
import "firebase/auth";
import "firebase/firestore";
For realtime database, you would add import "firebase/database".
Related
I am trying to update a Firebase Cloud Function that I havent touched for a year. Deployment went without issues back then.
Here is my setup: I have a root index.ts file, and functions are organized into folders.
root index.ts
import {initializeApp} from "firebase-admin";
// Initialize Firebase Admin
initializeApp();
export {notifyNewMessages} from "./notify_new_messages";
export {onUpdateUsers, onUpdateUserRatings} from "./on_update/index";
export {onUninstall} from "./on_uninstall/index";
and notifyNewMessages file starts like this
import {FirebaseError, firestore, messaging} from "firebase-admin";
import * as functions from "firebase-functions";
import i18n from "./localization";
import {Ask, Device, User} from "./models";
import DocumentSnapshot = firestore.DocumentSnapshot;
const fcm: messaging.Messaging = messaging();
Could this separated root file cause this problem?
Cheers,
It looks like you are using ES Modules, and as firebase has moved to modular SDK namespace versions require some modifications so try the following:
import * as admin from 'firebase-admin';
const app: admin.app.App = admin.initializeApp();
You can go through this docs for other changes to be made.
I'm trying to add SQlite to my ionic4 project, but get installation errors.
My NPM install was this:
ionic cordova plugin add cordova-sqlite-storage
npm install #ionic-native/sqlite
//ionic plugin add cordova-sqlite-storage ==> this one makes error
In main.js, I tried each of the following:
import SQLite from 'ionic-native';
import {SQLite} from 'ionic-native';
import SQLite from '#ionic-native/sqlite';
import {SQLite} from '#ionic-native/sqlite';
import { SQLite, SQLiteObject } from '#ionic-native/sqlite';
Here are the errors: a) npm warning, b) console error, and c) Chrome inspector for main.js
And here's the code from main.js (last line is where everything fails).
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App },
render : (h) => h(App),
mounted() {
this.storage = new SQLite();
*** I marked this question as answered, but there appears to be no answer yet. I'll keep working on it.
#ionic/vue is still in beta and the team is working on integrating it with the Vue CLI. They are also using Capacitor, not Cordova, as the official native bridge for this project. As such it is recommended to use Capacitor if at all possible. Should you go that route, their storage API is available in lieu of SQLite.
If you would like to persist with your Cordova project, the Ionic Storage abstraction won't be available so you would have to bypass Ionic altogether.
Install the plugin using the Cordova CLI (#ionic-native/sqlite is not required):
cordova plugin add cordova-sqlite-storage
Use the plugin directly e.g.
const db = window.sqlitePlugin.openDatabase({...})
db.executeSql('INSERT...', [...values], callbackFn, errorFn)
I installed firebase v-5.8.2 package through WIX's package manager. The installation process doesn't have any problem per se. After installation, I added "import * as firebase from 'firebase/app'", without any other code. When I run the project, it gave error message "can not find module 'fs'"
In the wix's forum, seems that someone had success experience with an earlier firebase version. Wondering if the v-5.8.2 has some problem with WIX.
import * as firebase from 'firebase/app'
"can not find module 'fs'"
You are importing it on a backend .jsw file, right?
NPM modules can only be imported on backend files and not on your page code.
You can export the functions from a backend file like below:
//serverSide.jsw
import firebase from 'firebase';
var app = require('firebase');
export function backendModule() {
//Your backend function code here
}
Then import the function on the frontend page code like below:
import {backendModule} from 'backend/serverSide.jsw';
$w.onReady(function () {
//TODO: write your page related code here...
});
If you are already importing on the backend file then try this below
import firebase from 'firebase';
I'm trying to use the firebase in a react native project
I installed the firebase in my project:
npm install --save firebase
and I'm importing it into my app.js
import firebase from 'firebase';
import React, { Component } from 'react';
import {
Platform,
Text,
View
} from 'react-native';
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<View >
<Text>Testando Firebase</Text>
</View>
);
}
}
and then the error is displayed:
Objects are not valida as a react child (found: object with
keys{&&typeof, type, key, ref, props, _owner, _store}). If you meant
to render a collection of children, use an array instead.
but when I remove the import from firebase, the app works perfectly.
Try to install the version 5.0.2. Use this command as administrator:
npm uninstall firebase
npm install --save firebase#5.0.2
As far as i see, the current version (5.0.4) is buggy!
You need to import as follow
import * as firebase from 'firebase';
You first must have firebase installed.
The solution is to uninstall the current version of Firebase and install an older version.
1st step npm uninstall firebase
2nd step npm i firebase#8.0.3
It was the version that worked for my case.
I have followed the tutorial at https://www.djamware.com/post/5a629d9880aca7059c142976/build-ionic-3-angular-5-and-firebase-simple-chat-app to build an Ionic app using Firebase's realtime database.
It works perfectly locally via ionic serve. I have also used the Ionic DevApp and again, it works perfectly.
I have now pushed my code to Ionic but during the build I get this error and the build process terminates:
[11:20:31] typescript: src/pages/chat/chat.ts, line: 7
Cannot find module 'Firebase'.
L7: import * as firebase from 'Firebase';
Error: Failed to transpile program
at new BuildError (/usr/src/app/node_modules/#ionic/app-scripts/dist/util/errors.js:16:28)
at /usr/src/app/node_modules/#ionic/app-scripts/dist/transpile.js:159:20
at Promise ()
at transpileWorker (/usr/src/app/node_modules/#ionic/app-scripts/dist/transpile.js:107:12)
at Object.transpile (/usr/src/app/node_modules/#ionic/app-scripts/dist/transpile.js:64:12)
at /usr/src/app/node_modules/#ionic/app-scripts/dist/build.js:109:82
at
npm info lifecycle fanslide#0.0.1~build: Failed to exec build script
In chat.ts I have:
import * as firebase from 'Firebase';
Inside package.json I can see:
"firebase": "^4.8.0",
I am not sure what I have done wrong and why this works locally but not when the build takes place on Ionic's server.
I managed to overcome this issue and successfully complete a build in Ionic by changing:
import * as firebase from 'Firebase';
To:
import firebase from 'firebase';