0

编码:

(global as any).XMLHttpRequest = require("xhr2");

import firebase from "firebase/app";
import "firebase/firestore";

// All are fake values
const firebaseConfig = {
  apiKey: "dsfds",
  authDomain: "sdf.firebaseapp.com",
  databaseURL: "https://sdfs.firebaseio.com",
  projectId: "dssdf",
  storageBucket: "sdsdfsdf.appspot.com",
  messagingSenderId: "wearwefas",
  appId: "asdfgerhdfgdettgerg",
  measurementId: "sdfgsregserg",
};

const app = firebase.initializeApp(firebaseConfig);
app
  .firestore()
  .doc("foo/bar")
  .get()
  .then((doc) => {
    console.log(doc.data());
  })
  .catch((e) => {
    throw e;
  });

Firebase SDK 版本:7.19.1

该代码与 esbuild 捆绑在一起,生成与 rollup 相同的捆绑包。

在终端中运行时,它输出:

[2020-09-10T13:35:55.539Z]  @firebase/app:
      Warning: This is a browser-targeted Firebase bundle but it appears it is being
      run in a Node environment.  If running in a Node environment, make sure you
      are using the bundle specified by the "main" field in package.json.

      If you are using Webpack, you can specify "main" as the first item in
      "resolve.mainFields":
      https://webpack.js.org/configuration/resolve/#resolvemainfields

      If using Rollup, use the rollup-plugin-node-resolve plugin and specify "main"
      as the first item in "mainFields", e.g. ['main', 'module'].
      https://github.com/rollup/rollup-plugin-node-resolve

Discarding entity body for GET requests
[2020-09-10T13:36:05.559Z]  @firebase/firestore: Firestore (7.19.1): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
(node:4104) UnhandledPromiseRejectionWarning: FirebaseError: Failed to get document because the client is offline.
    at new n2 (F:\Workspaces\Git Repos\lookahead\packages\cli\lib\index.js:5357:20)
    at next (F:\Workspaces\Git Repos\lookahead\packages\cli\lib\index.js:14649:50)
    at Timeout._onTimeout (F:\Workspaces\Git Repos\lookahead\packages\cli\lib\index.js:13615:19)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)
(node:4104) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:4104) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Discarding entity body for GET requests
Discarding entity body for GET requests
Discarding entity body for GET requests

我已连接到互联网,但它显示我处于离线状态。我该如何解决??

4

1 回答 1

1

只要您使用--platform=node.

于 2020-09-12T03:01:11.180 回答