Skip to content

Conversation

@tylim88
Copy link

@tylim88 tylim88 commented Jul 20, 2022

as for now esModuleInterop is not enabled, this has caused some issues when importing, for example:

import firestore from 'firebase-admin/firestore'
const st = firestore.FieldValue.serverTimestamp() // will not works, `firestore` is undefined

with @babel/preset-env, it is translated into

"use strict";

var _firestore = _interopRequireDefault(require("firebase-admin/firestore"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var st = _firestore.default.FieldValue.serverTimestamp();

playground

this import will not work because, in the built code, we have something like this
image

in the built code, the __esModule prop is set to true

the problem: import x from 'y' is equivalent to const x = require('y').default but the default prop is not defined(with __esModule set to true, _interopRequireDefault will not return { default: obj } and _firestore.default will become undefined)

the solution is to simply enable esModuleInterop in ts config

======================================
I did the changes needed for esModuleInterop to work and fix some types along the way:

  1. enable esModuleInterop in ts config
  2. change import * as x to import x for multiple files
  3. fix some type issues in:
  • test/integration/auth.spec.ts
  • test/integration/firestore.spec.ts

no changes in public api

2. change import as x to import x
3. fix some type issue:
i. test/integration/auth.spec.ts
ii. test/integration/firestore.spec.ts
@google-cla
Copy link

google-cla bot commented Jul 20, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@tylim88
Copy link
Author

tylim88 commented Jul 20, 2022

my deduction is incorrect

turn out the reason is that it simply doesn't have a default export

this PR is not meaningful, close

@tylim88 tylim88 closed this Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant