node.js - 未处理的PromiseRejection警告: Error: error:0906D06C:PEM routines:PEM_read_bio:no start line

标签 node.js reactjs firebase express

我有一个带有 Node/express 服务器、React 客户端和 firebase firestore 作为数据库的应用程序。当我对 firebase 数据库执行操作时,我的代码似乎可以工作,但数据没有显示在 firestore 控制台中,并且出现以下错误。

我实现了以下解决方案,但它不起作用: https://stackoverflow.com/a/40321130/1438277

我正在运行 npm 6.9.0 和 Node v11.8.0

谢谢

Unhandled Rejection at: Promise Promise {
[0]   <rejected> Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
[0]       at Sign.sign (internal/crypto/sig.js:84:29)
[0]       at Object.sign (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/jwa/index.js:152:45)
[0]       at Object.jwsSign [as sign] (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/jws/lib/sign-stream.js:32:24)
[0]       at GoogleToken.requestToken (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/gtoken/build/src/index.js:180:31)
[0]       at GoogleToken.getTokenAsync (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/gtoken/build/src/index.js:119:21)
[0]       at GoogleToken.getToken (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/gtoken/build/src/index.js:61:21)
[0]       at JWT.refreshTokenNoCache (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/google-auth-library/build/src/auth/jwtclient.js:129:36)
[0]       at JWT.refreshToken (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/google-auth-library/build/src/auth/oauth2client.js:148:24)
[0]       at JWT.getRequestMetadataAsync (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/google-auth-library/build/src/auth/oauth2client.js:265:28)
[0]       at JWT.getRequestMetadataAsync (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/google-auth-library/build/src/auth/jwtclient.js:76:26)
[0]       at JWT.getRequestHeaders (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/google-auth-library/build/src/auth/oauth2client.js:244:32)
[0]       at SingleCallCredentials.call_credentials_1.CallCredentials.createFromMetadataGenerator [as metadataGenerator] (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/index.js:74:39)
[0]       at Promise (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/call-credentials.js:64:18)
[0]       at new Promise (<anonymous>)
[0]       at SingleCallCredentials.generateMetadata (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/call-credentials.js:63:16)
[0]       at Promise.all.creds.map (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/call-credentials.js:47:75) } reason: Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
[0]     at Sign.sign (internal/crypto/sig.js:84:29)
[0]     at Object.sign (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/jwa/index.js:152:45)
[0]     at Object.jwsSign [as sign] (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/jws/lib/sign-stream.js:32:24)
[0]     at GoogleToken.requestToken (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/gtoken/build/src/index.js:180:31)
[0]     at GoogleToken.getTokenAsync (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/gtoken/build/src/index.js:119:21)
[0]     at GoogleToken.getToken (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/gtoken/build/src/index.js:61:21)
[0]     at JWT.refreshTokenNoCache (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/google-auth-library/build/src/auth/jwtclient.js:129:36)
[0]     at JWT.refreshToken (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/google-auth-library/build/src/auth/oauth2client.js:148:24)
[0]     at JWT.getRequestMetadataAsync (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/google-auth-library/build/src/auth/oauth2client.js:265:28)
[0]     at JWT.getRequestMetadataAsync (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/google-auth-library/build/src/auth/jwtclient.js:76:26)
[0]     at JWT.getRequestHeaders (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/google-auth-library/build/src/auth/oauth2client.js:244:32)
[0]     at SingleCallCredentials.call_credentials_1.CallCredentials.createFromMetadataGenerator [as metadataGenerator] (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/index.js:74:39)
[0]     at Promise (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/call-credentials.js:64:18)
[0]     at new Promise (<anonymous>)
[0]     at SingleCallCredentials.generateMetadata (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/call-credentials.js:63:16)
[0]     at Promise.all.creds.map (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/call-credentials.js:47:75)
[0] (node:3612) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 2)
[0] Unhandled Rejection at: Promise Promise {
[0]   <rejected> { Error: Getting metadata from plugin failed with error: error:0906D06C:PEM routines:PEM_read_bio:no start line
[0]       at Http2CallStream.call.on (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/client.js:102:45)
[0]       at Http2CallStream.emit (events.js:202:15)
[0]       at Http2CallStream.EventEmitter.emit (domain.js:439:20)
[0]       at Http2CallStream.endCall (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/call-stream.js:74:18)
[0]       at /Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/call-stream.js:355:18
[0]       at processTicksAndRejections (internal/process/next_tick.js:81:5)
[0]     code: 2,
[0]     details:
[0]      'Getting metadata from plugin failed with error: error:0906D06C:PEM routines:PEM_read_bio:no start line',
[0]     metadata: Metadata { internalRepr: Map {} } } } reason: { Error: Getting metadata from plugin failed with error: error:0906D06C:PEM routines:PEM_read_bio:no start line
[0]     at Http2CallStream.call.on (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/client.js:102:45)
[0]     at Http2CallStream.emit (events.js:202:15)
[0]     at Http2CallStream.EventEmitter.emit (domain.js:439:20)
[0]     at Http2CallStream.endCall (/Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/call-stream.js:74:18)
[0]     at /Users/antoine/Desktop/jf_express_with_react/server/node_modules/@grpc/grpc-js/build/src/call-stream.js:355:18
[0]     at processTicksAndRejections (internal/process/next_tick.js:81:5)
[0]   code: 2,
[0]   details:
[0]    'Getting metadata from plugin failed with error: error:0906D06C:PEM routines:PEM_read_bio:no start line',
[0]   metadata: Metadata { internalRepr: Map {} } }

这是我从 Express 服务器进行的数据库调用:

const admin = require('firebase-admin')
const config = require('./config.js')

exports.createAsin = p => {
  try {
    let addDoc = config.db.collection('asins').add({
      uid: p.uid,
      asin: p.asin,
      mapPrice: p.mapPrice,
      data: []
    })
    console.log('db: ASIN created')
    return p
  } catch (e) {
    console.log('db: error creating ASIN /', e)
    return null
  }
}

最佳答案

Firebase(或任何数据库)调用是异步事件,因此您需要使用 Promise 或回调函数来避免 Promise 拒绝错误。这是 Javascript Promise 的文档: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

这里有一篇非常有用的文章,介绍如何将它们与 Firebase 一起使用: https://howtofirebase.com/promises-for-firebase-bbb9d0d595ed

对于您的示例,您可以执行类似的操作

exports.createAsin = async p => {
  try {
    let addDoc = await config.db.collection('asins').add({
      ...
    })
    console.log('db: ASIN created')
    return p
  } catch (e) {
    ...
  }
}

关于node.js - 未处理的PromiseRejection警告: Error: error:0906D06C:PEM routines:PEM_read_bio:no start line,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56379140/

相关文章:

node.js - Nodejs + Express : make http request wait for udp response

reactjs - Cypress.io 身份服务器

javascript - 如何在 firebase 上获取当前用户

node.js - 使用 enctype ="multipart/form-data"时出现 CSRF 错误

node.js - 在同一个请求express node js中上传文件和JSON数据

node.js - Sequelize 不会创建 hasMany 关联,而是创建在 DB 中定义的外键

coffeescript - 使用 Foundation 和 React 的动态 HTML

javascript - 动态导入的组件被视为 JSX 元素

python - 为什么我的 Firebase Firestore 查询不在 order_by 中?

android - Kotlin 内联函数用于检查用户是否经过身份验证?