Fix 0909006C PEM error on remote deploys

Published on August 7th, 2019

error icon

First a little bit of backstory. About one month ago I was working on fetching top posts from this blog from Google Analytics and I encountered this pretty cryptic error.

Error in netlify console

Everything was working perfectly on local environment but on Travis CI and Netlify it was failing. After reading countless Stack Overflow questions and copy-pasting my API keys multiple times I stumbled on this issue comment.

The problem was that Netlify and Travis CI were escaping \ in newline characters so they would look like this \\n.

Solution

Add this to your code.

const replace = require('lodash.replace')

const apiKey = replace(process.env.YOUR_API_KEY, new RegExp('\\\\n', 'g'), '\n')

Make sure to install lodash replace module.

yarn add lodash.replace

And don’t forget to use your “escaped” key instead of original one for authentication.

someCoolServiceThatNeedsApiKey(
  apiKey
  // ...
)