firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Upgrade from 10.6.0 to 10.7.0 or 10.8.0: no such file or directory, open 'node:stream'

Open PMG-VascoSaavedra opened this issue 1 year ago • 2 comments

Operating System

Windows

Browser Version

n/a

Firebase SDK Version

10.7.0; 10.8.0

Firebase SDK Product:

Auth, Database, Firestore

Describe your project's tooling

React App, yarn, Jest

Describe the problem

When updating from firebase 10.6.0 to 10.7.0/10.8.0, i get the following error when executing the Jest tests:

ENOENT: no such file or directory, open 'node:stream' at Runtime.readFile (../../../node_modules/jest-runtime/build/index.js:1987:21) at Object. (../../../node_modules/@fastify/busboy/lib/main.js:3:24)

This seems to be related to a change on version 10.7.0:

Replaced node-fetch dependency with the latest version of undici in Node.js SDK builds for Auth, Firestore, Cloud Functions, and Storage. See GitHub issue #7280.

Steps and code to reproduce issue

I''ve created a small project to replicate the problem using firebase 10.8.0 version (all versions from 10.7.0 produce the same error):

  1. Download and unzip project file: firebase_issue.zip
  2. Install libs > yarn install
  3. Run tests > yarn test

Tests will fail with the following error: ENOENT: no such file or directory, open 'node:stream' at Runtime.readFile (../../../node_modules/jest-runtime/build/index.js:1987:21) at Object. (../../../node_modules/@fastify/busboy/lib/main.js:3:24)

When using version 10.6.0, the tests run successfully.

PMG-VascoSaavedra avatar Feb 13 '24 23:02 PMG-VascoSaavedra

Hi @PMG-VascoSaavedra, thank you for reaching out to us. I was able to replicate the reported behavior. Let me check what we can do for this issue or bring someone here that can provide more context about it. I’ll update this thread if I have any information to share.

jbalidiong avatar Feb 15 '24 12:02 jbalidiong

Thank you!

PMG-VascoSaavedra avatar Feb 15 '24 17:02 PMG-VascoSaavedra

So the root problem behind things like this is usually that you are trying to run something in a browser environment (or browser-like environment, which should be jsdom for Jest), but you are pulling in the Firebase Node bundle, and not the browser bundle.

The file you want for Jest is node_modules/@firebase/auth/dist/browser-cjs/index.js. The file you are getting is node_modules/@firebase/auth/dist/node/index.js. This is a problem with Jest's resolver looking at the wrong field in package.json, which happens in different ways in different versions of Jest.

In your case, you're using an older version of Jest because you're using react-scripts, which is the engine behind Create React App, which hasn't been updated in a long time and is bringing in an old version of Jest. It seems this version defaults to looking at the main field in a dependency's package.json, which is pointing at the Node bundle for Firebase auth, which is standard.

A couple of possible solutions for you are to either update Jest to a newer version (which might require ejecting from react-scripts), or to modify your Jest config to resolve to the package.json field exports.node.require (which I think is the default for newer versions of Jest). I'm not really sure how to configure that version of Jest so you might have to consult elsewhere.

hsubox76 avatar Feb 22 '24 22:02 hsubox76

Thank you for your analysis and feedback.

I'll look into it, and i'll get back to you once i have found a way to correct this issue!

PMG-VascoSaavedra avatar Feb 22 '24 23:02 PMG-VascoSaavedra

Hey @PMG-VascoSaavedra. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Feb 29 '24 02:02 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@PMG-VascoSaavedra if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Mar 07 '24 02:03 google-oss-bot