I encountered the following error while integrating Firebase with ReactJs:

1
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:

1
import keys from './keys';

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

Here’s what keys.js looked like:

1
2
3
4
5
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:

1
2
3
4
5
6
7
8
9
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:

1
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.