firebase / firebase-functions-test

MIT License
232 stars 48 forks source link

Cannot import `firebase-functions/v2` #151

Closed dima11221122 closed 2 years ago

dima11221122 commented 2 years ago

Version info

firebase-functions-test: 2.1.0

firebase-functions: 3.21.2

firebase-admin: 10.2.0

Test case

import functions from 'firebase-functions-test';

Steps to reproduce

Expected behavior

No errors

Actual behavior

 Cannot find module 'firebase-functions/v2' from 'node_modules/firebase-functions-test/lib/cloudevent/mocks/pubsub/pubsub-on-message-published.js'

    Require stack:
      node_modules/firebase-functions-test/lib/cloudevent/mocks/pubsub/pubsub-on-message-published.js
      node_modules/firebase-functions-test/lib/cloudevent/mocks/partials.js
      node_modules/firebase-functions-test/lib/cloudevent/generate.js
      node_modules/firebase-functions-test/lib/v2.js
      node_modules/firebase-functions-test/lib/main.js
      node_modules/firebase-functions-test/lib/features.js
      node_modules/firebase-functions-test/lib/index.js
      src/sync/syncFunctions/utils/init-firestore.ts
      setupTests.ts

      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
      at Object.<anonymous> (node_modules/firebase-functions-test/lib/cloudevent/mocks/pubsub/pubsub-on-message-published.js:4:14)
TheIronDev commented 2 years ago

Thanks for opening up the issue!

I spun up a new project but was not able to reproduce this.

Do you have a repo I can look at? If not, do you have an example of the function and test that you are running?

Thank you again!

ericallam commented 2 years ago

I got this error message as well, when upgrading my project. I was importing firebase-functions-test from a jest setup file and getting the same error as @dima11221122. After upgrading my jest/ts-jest/ts-node dependencies to the latest versions this error went away.

TheIronDev commented 2 years ago

@ericallam Oh man, I totally forgot about that!!

@dima11221122

If you're using jest < 28, you'll run into this issue.

Please try upgrading to jest@28 and let me know if you can still reproduce this.

More info:

I'll open a pr to include jest@28 as a peer dep to reduce this problem. Thank you for raising this!

dima11221122 commented 1 year ago

Thank you guys for your help, after I upgraded to jest 28 the problem is gone