Skip to content

@firebase/firestore: Firestore (9.23.0): FIRESTORE (9.23.0) INTERNAL ASSERTION FAILED: Unexpected state #7712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fkolar opened this issue Oct 20, 2023 · 10 comments

Comments

@fkolar
Copy link

fkolar commented Oct 20, 2023

Operating System

Mac OS X 13.6

Browser Version

Headless

Firebase SDK Version

9.23

Firebase SDK Product:

Firestore

Describe your project's tooling

I am using Angular wth NX workspace that is running JEST to execute test. I am using @angular/fire 7.6.1

Describe the problem

I am unable to execute a test that is failing on

[2023-10-20T09:08:32.007Z]  @firebase/firestore: Firestore (9.23.0): FIRESTORE (9.23.0) INTERNAL ASSERTION FAILED: Unexpected state

      at Logger.defaultLogHandler [as _logHandler] (node_modules/@firebase/logger/src/logger.ts:115:57)
      at Logger.Object.<anonymous>.Logger.error (node_modules/@firebase/logger/src/logger.ts:210:5)
      at logError (node_modules/@firebase/firestore/src/util/log.ts:59:15)
      at fail (node_modules/@firebase/firestore/src/util/assert.ts:35:3)
      at hardAssert (node_modules/@firebase/firestore/src/util/assert.ts:54:5)
      at fromBytes (node_modules/@firebase/firestore/src/remote/serializer.ts:264:5)
      at fromWatchChange (node_modules/@firebase/firestore/src/remote/serializer.ts:502:25)
      at PersistentListenStream.onMessage (node_modules/@firebase/firestore/src/r

I saw many similar issues over here but unfortunatelly I have no idea how to fix it in this setup. One more thing that I need to say, when I run a test to create a document it works, but when I try to retrieve it this is where I get this error.

Steps and code to reproduce issue

I have created the repo to test. Please follow quict instruction in the REDME. Thank you

https://github.com/fkolar/firebase-test

@fkolar fkolar added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Oct 20, 2023
@fkolar
Copy link
Author

fkolar commented Oct 20, 2023

The same works with karma:

https://github.com/fkolar/firebase-karma

When I added a console.log to the file that does the assert

function fromBytes(serializer, value) {
    if (serializer.useProto3Json) {
        hardAssert(value === undefined || typeof value === 'string');
        return ByteString.fromBase64String(value ? value : '');
    }
    else {
          console.log('@@@@@@@@@@@@@@@@@@@@@: ', value)
          console.log('@@@@@@@@@@@@@@@@@@@@@: ', value === undefined || value instanceof Uint8Array)
        hardAssert(value === undefined || value instanceof Uint8Array);
        return ByteString.fromUint8Array(value ? value : new Uint8Array());
    }
}

The output is

 @@@@@@@@@@@@@@@@@@@@@:  <Buffer >
    @@@@@@@@@@@@@@@@@@@@@:  false

Uploading Screenshot 2023-10-20 at 19.57.03.png…

@jbalidiong jbalidiong added needs-attention and removed new A new issue that hasn't be categoirzed as question, bug or feature request labels Oct 20, 2023
@ehsannas
Copy link
Contributor

Thanks for reporting @fkolar and for providing a reproduction repository.

@fkolar
Copy link
Author

fkolar commented Oct 23, 2023

I wonder if you guys have any workaround in meanwhile. I dont really want to more all to Karma yet.

@MarkDuckworth
Copy link
Contributor

I can reproduce the issue with the provided repo, but after spending time trying to resolve it, I don't have a workaround for you. There is another thread with several suggestions that may be helpful for you: #6931.

@hsubox76, do you have any thoughts on this one?

@MarkDuckworth
Copy link
Contributor

@fkolar To clarify, I think what is happening is that your build is choosing the wrong entry point/bundle for the Firebase SDK when building for tests. E.g. it's using the node entry point instead of the browser entry point. I'm not familiar enough with your tool chain to advise you how to change this.

@hsubox76
Copy link
Contributor

Thanks @fkolar for the repros, by the way, they were very helpful.

The one bit of info I can offer is that the Jest test grabs the Node CJS bundle (@firebase/firestore/dist/index.node.cjs.js) while the Karma test grabs the browser ESM bundle (@firebase/firestore/dist/index.esm2017.js). I think the bundle you actually want in Jest is the browser CJS bundle (@firebase/firestore/dist/index.cjs.js).

As for how to get it, I managed to do so with a custom resolver:

Add resolver: "<rootDir>/jest.resolver.js" to jest.config.ts

Create jest.resolver.js in the root dir with the contents:

// jest.resolver.js
module.exports = (path, options) => {
  // Call the defaultResolver, so we leverage its cache, error handling, etc.
  return options.defaultResolver(path, {
    ...options,
    conditions: ['browser', 'require']
  });
};

This doesn't seem very robust, especially as it will affect all modules (including non-firebase ones) but basically you have to tinker with condition order until you make sure you're resolving to this condition for firestore:

"require": "./dist/index.cjs.js",

As an aside, when I did that, I got past the error above but ran into a timeout error which may be something else, or just because I haven't got the emulator set up.

@hsubox76
Copy link
Contributor

You may also be able to use the packageFilter option to make a resolution change only apply to @firebase/firestore. There's an example of how to use it here, but I wouldn't make the exact changes they make there - it won't work, it will just end up resolving to index.node.cjs.js again, as that's what "main" is. I'd probably modify exports.node.require (I think that's the field Jest will always grab) to point to index.cjs.js

@google-oss-bot
Copy link
Contributor

Hey @fkolar. 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!

@fkolar
Copy link
Author

fkolar commented Nov 2, 2023

This is great info, in meantime I am using Karma and all works well, but I will try to this resolver thing..

@dan-hale
Copy link

I was getting a similar error when using IndexDB persistence with Firestore. Just ended up disabling persistence and things are working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants