TypeError: module.exports.v1 is not a constructor, error thrown from google-cloud/firestore when using firebase-admin sdk

Viewed 357

Recently I encountered the above error (TypeError: module.exports.v1 is not a constructor) when trying to run firebase-firestore related tests. Earlier I had no issue running the tests but after doing a npm install was getting the above error. The source of the error is from google-cloud/firestore which is required by firebase-admin. Tried several options but it doesn't seems to get resolved. I then tried with an older node-module and it worked as expected.

4 Answers

The problem was due to the test framework I've been using. Once I changed from jest to mocha the problem got solved.

When I updated firebase admin sdk from 8.4.0 to higher then I had same error in running jest test code.

I fixed it to add --env node option for jest.

jest --env node

I hit this error when I left out an await on an async function. That caused my code to continue running after the jest environment had been torn down.

There was a message that said ReferenceError: You are trying to import a file after the Jest environment has been torn down. which should have been a tip that I was running async code and not waiting for completion.

We needed to upgrade node from v8.11.3 to v8.16.2.

Related