I encountered the following error while integrating Firebase with ReactJs:

Uncaught TypeError: Cannot use 'in' operator to search for 'service Account' in undefined

I'm writing this post to share the solution that worked for me.

I needed to import a javascript object from one file into another using module.exports.

In my React component, I imported the object as follows:

import keys from './keys';

(I was trying to import API keys from a separate file).

Here's what keys.js looked like:

module.exports = {
  apiKey: 'my API key',
  authDomain: 'my auth domain',
  databaseURL: 'my database url'
};

This is the incorrect way to export javascript objects. The proper way is:

apiKey: 'my API key',
authDomain: 'my auth domain',
databaseURL: 'my database url'

module.exports = {
  apiKey: apiKey,
  authDomain: authDomain,
  databaseURL: databaseURL
};

TL;DR

If you encounter the following error:

Uncaught TypeError: Cannot use 'in' operator to search for 'service Account' in undefined

Make sure that you are exporting and importing correctly.

Other Things To Check

  • Ensure that you didn't write module.export instead of module.exports by mistake.