简体   繁体   English

在 Google App Script 上安装 Firebase SDK v9?

[英]Install Firebase SDK v9 on Google App Script?

I am trying to use Firebase SDK on my Google App Script app.我正在尝试在我的 Google App Script 应用程序上使用 Firebase SDK。 The documentation says it needs installing npm install firebase which is not possible via Google App Script.文档说它需要安装npm install firebase这无法通过 Google App Script 实现。

So the following step would be:所以下面的步骤是:

// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: "***",
  authDomain: "myapp.firebaseapp.com",
  databaseURL: "https://myapp-default-rtdb.europe-west1.firebasedatabase.app",
  projectId: "myappurl",
  storageBucket: "myappurl.appspot.com",
  messagingSenderId: "267227785525",
  appId: "***",
  measurementId: "G-K5CP51FRXR"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);

But i get the error:但我得到错误:

SyntaxError: Cannot use import statement outside a module linea: SyntaxError: 不能在模块行之外使用 import 语句:

It looks like i am not declaring it as a module.看起来我没有将它声明为模块。 I have checked for tutorials and help but only find the how-to for Node.js, Google Script is not talked about.我已经查看了教程和帮助,但只找到了 Node.js 的操作方法,未提及 Google Script。

Note: I have installed 'FirebaseApp' library.注意:我已经安装了“FirebaseApp”库。

Anyone knows how to do what i need?任何人都知道如何做我需要的? Is that even possible to use SDK v9 on GAS?甚至可以在 GAS 上使用 SDK v9 吗?

While Google Apps Script and Node.js uses JavaScript as programming language, Node.js has several features that aren't included in Google Apps Script, one of them is the the npm packages handling.虽然 Google Apps 脚本和 Node.js 使用 JavaScript 作为编程语言,但 Node.js 具有 Google Apps 脚本中未包含的多项功能,其中之一是 npm 包处理。

One option might be to use the npm package "as a client-side library".一种选择可能是使用 npm package “作为客户端库”。 Please start by reading https://developers.google.com/apps-script/guides/web , then checkout Use npm package on client side .请先阅读https://developers.google.com/apps-script/guides/web ,然后在客户端结帐使用 npm package

Some client-side libraries might work as server side JavaScript. Nowadays Google Apps Script has two runtimes, but one, Rhino, depends on the old Google Apps Script IDE that will be retired soon.一些客户端库可能作为服务器端运行 JavaScript。现在 Google Apps Script 有两个运行时,但是一个,Rhino,依赖于即将停用的旧 Google Apps Script IDE。 To learn about the new runtime, V8, please read https://developers.google.com/apps-script/guides/v8-runtime .要了解新的运行时 V8,请阅读https://developers.google.com/apps-script/guides/v8-runtime

Some npm packages have being "converted" into Google Apps Script libraries.一些 npm 包已被“转换”为 Google Apps 脚本库。 You might try to find on by searching this site, a service like GitHub, etc. Another option is to ask for a software recommendation on https://softwarerecs.stackexchange.com .您可能会尝试通过搜索此站点来查找 GitHub 等服务。另一种选择是在https://softwarerecs.stackexchange.com上寻求软件推荐。

Another option is to use the Firebase REST API directly in Google Apps Script by using the Url Fetch Service .另一种选择是通过使用Url Fetch Service直接在 Google Apps 脚本中使用 Firebase REST API 。

Related有关的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM