Skip to content
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

Fix Named export 'Integer' not found error in es module node project #7227

Conversation

dconeybe
Copy link
Contributor

The Firestore Node bundles now all have a dependency on @firebase/webchannel-wrapper (previously, only the "browser" bundles had this dependency). If a project consuming the Firebase SDK does not define "type": "module" in its package.json, or defines "type": "commonjs" then the Firestore bundle index.node.cjs.js is used. This bundle has the line

var webchannelWrapper = require('@firebase/webchannel-wrapper');

which works.

However, if a project consuming the Firebase SDK does defines "type": "module" then the Firestore bundle index.node.mjs is used. This bundle has the line

import { Integer, Md5 } from '@firebase/webchannel-wrapper';

which fails at runtime with this error:

file:///home/dconeybe/tmp/bftest/mjs/node_modules/@firebase/firestore/dist/index.node.mjs:7
import { Integer, Md5 } from '@firebase/webchannel-wrapper';
         ^^^^^^^
SyntaxError: Named export 'Integer' not found. The requested module '@firebase/webchannel-wrapper' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@firebase/webchannel-wrapper';
const { Integer, Md5 } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Node.js v18.14.2

Process finished with exit code 1

This seems to be because the @webchannel-wrapper bundle index.esm2017.js is being incorrectly loaded as a commonjs module, when, in fact, it is an es module.

This PR fixes the problem by simply changing the .js extension to .mjs to indicate that it is an es module and not a commonjs module.

@dconeybe dconeybe self-assigned this Apr 14, 2023
@changeset-bot
Copy link

changeset-bot bot commented Apr 14, 2023

⚠️ No Changeset found

Latest commit: 25bbd56

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dconeybe dconeybe changed the base branch from master to mila/BloomFilter April 14, 2023 17:09
@google-oss-bot
Copy link
Contributor

Size Report 1

Affected Products

  • @firebase/firestore

    TypeBase (ecb4454)Merge (7f1b85f)Diff
    browser278 kB282 kB+3.46 kB (+1.2%)
    esm5346 kB350 kB+3.77 kB (+1.1%)
    main554 kB561 kB+6.63 kB (+1.2%)
    module278 kB282 kB+3.46 kB (+1.2%)
    react-native279 kB282 kB+3.41 kB (+1.2%)
  • bundle

    TypeBase (ecb4454)Merge (7f1b85f)Diff
    firestore (Persistence)284 kB298 kB+13.9 kB (+4.9%)
    firestore (Query Cursors)222 kB236 kB+13.9 kB (+6.3%)
    firestore (Query)220 kB234 kB+13.9 kB (+6.3%)
    firestore (Read data once)207 kB221 kB+13.9 kB (+6.7%)
    firestore (Realtime updates)209 kB223 kB+13.9 kB (+6.7%)
    firestore (Transaction)190 kB200 kB+10.6 kB (+5.6%)
    firestore (Write data)190 kB200 kB+10.6 kB (+5.6%)
  • firebase

    TypeBase (ecb4454)Merge (7f1b85f)Diff
    firebase-compat.js757 kB771 kB+13.7 kB (+1.8%)
    firebase-firestore-compat.js324 kB337 kB+13.7 kB (+4.2%)
    firebase-firestore.js327 kB341 kB+13.8 kB (+4.2%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/ORogQOQxJA.html

@dconeybe
Copy link
Contributor Author

Note: This PR is being superseded by #7228.

@dconeybe dconeybe closed this Apr 14, 2023
@dconeybe dconeybe deleted the dconeybe/bloom_filter_webchannel_wrapper_mjs_fix branch April 14, 2023 18:52
@firebase firebase locked and limited conversation to collaborators May 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants