vuejs / vuefire

🔥 Firebase bindings for Vue.js
https://vuefire.vuejs.org
MIT License
3.82k stars 323 forks source link

`databaseDefaultSerializer` exported incorrecly #1481

Closed tlserver closed 5 months ago

tlserver commented 5 months ago

Reproduction

Please find the reproduction example in this codesandbox.

Unfortunately, there is no option to make it writable to the public. To edit, please sign in and fork the sandbox.

Steps to reproduce the bug

  1. Add the following import statement to your code:
    import { databaseDefaultSerializer } from "vuefire";
  2. It fails on page loaded.

Expected behavior

The import statement should successfully import the createRecordFromDatabaseSnapshot() function because, in dist/index.d.mts:21 (version 3.1.21, which may vary in other versions), it is defined and exported as databaseDefaultSerializer:

// line 21
declare function createRecordFromDatabaseSnapshot(/* ... */): /* ... */;

// line 726
export { /* ... */, createRecordFromDatabaseSnapshot as databaseDefaultSerializer, /* ... */ };

Actual behavior

An error is thrown with the following message:

Uncaught SyntaxError: The requested module '/node_modules/.vite/deps/vuefire.js?v=05c98cd7' does not provide an export named 'databaseDefaultSerializer'

This error message does not appear in the CodeSandbox console but is shown in the browser console. image

Additional Information

A search for databaseDefaultSerializer in dist/index.mjs returns no matches. It appears that the aliasing of createRecordFromDatabaseSnapshot as databaseDefaultSerializer is mistakenly placed within a type export block in src/index.ts:24-30:

export type {
  DatabaseSnapshotSerializer,
  _RefDatabase,
  VueDatabaseDocumentData,
  VueDatabaseQueryData,
  createRecordFromDatabaseSnapshot as databaseDefaultSerializer,
} from './database/utils'

Should it not be included in a regular export instead?

export {
  createRecordFromDatabaseSnapshot as databaseDefaultSerializer,
} from './database/utils'
posva commented 5 months ago

Yes, it shouldn’t be a type 😅 Feel free to open the PR since you already found the fix