从node.js错误中获取Firestore文档

问题描述

代码:

(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捆绑在一起,后者与汇总相同。

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

[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

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

解决方法

只要您使用--platform=node,这应该在esbuild版本0.7.0(刚刚发布)中起作用。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...