UnhandledPromiseRejectionWarning: E​​rror: error:0906D06C:PEM routines:PEM_read_bio:no start line

Posted

技术标签:

【中文标题】UnhandledPromiseRejectionWarning: E​​rror: error:0906D06C:PEM routines:PEM_read_bio:no start line【英文标题】:UnhandledPromiseRejectionWarning: Error: error:0906D06C:PEM routines:PEM_read_bio:no start line 【发布时间】:2019-10-16 03:53:42 【问题描述】:

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

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

我正在运行 npm 6.9.0 和节点 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   

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

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
  

【问题讨论】:

我认为这个承诺拒绝问题,Nedd 在你的代码中找到你的承诺在哪里被破坏了。您可以通过事件process.on('unhandledRejection', (reason, p) =&gt; console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); )找到或调试它;或者你可以从Here获取描述 我已更新问题以包含我现在得到的错误。谢谢! 知道什么可能导致错误吗?谢谢 【参考方案1】:

Firebase(或任何数据库)调用是异步事件,因此您需要使用 Promise 或回调函数来避免 Promise 拒绝错误。这是 javascript 承诺的文档: 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) 
    ...
  

【讨论】:

感谢您的贡献 :) 我按照您的建议重写了该函数,但仍然出现相同的错误。我从未见过与 Firebase 相关的此类错误,所以我认为这不是问题所在,但也许吧。【参考方案2】:

我终于弄明白了:我的 Firebase json 认证文件被放置在一个 .env 文件中,这就是导致错误的原因。我将它移到一个单独的 json 文件中(并将其添加到 .gitignore)并且它可以工作。呸!

【讨论】:

以上是关于UnhandledPromiseRejectionWarning: E​​rror: error:0906D06C:PEM routines:PEM_read_bio:no start line的主要内容,如果未能解决你的问题,请参考以下文章

[Unhandled promise rejection: TypeError: null is not an object (evaluating '_reactNativeImageCropPic

等待 - 捕获错误 - UnhandledPromiseRejectionWarning

批量删除如何工作?

7月工作知识总计:

未处理的承诺拒绝 |重启命令

未处理的承诺拒绝警告(Cordova Angular)