googleapis / nodejs-firestore

Node.js client for Google Cloud Firestore: a NoSQL document database built for automatic scaling, high performance, and ease of application development.
https://cloud.google.com/firestore/
Apache License 2.0
640 stars 149 forks source link

tsc compile error #747

Closed lookfirst closed 5 years ago

lookfirst commented 5 years ago

Current latest (2.2.9) of everything.

Suddenly getting this when running tsc on my firebase functions...

Adding this fixes it...

    "skipLibCheck": true,

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "importHelpers": true,
    "lib": [
      "es2019"
    ]
  },
  "compileOnSave": true,
  "include": [
    "./src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

Errors:

tsc

node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: DocumentData, UpdateData, Firestore, GeoPoint, Transaction, WriteBatch, WriteResult, DocumentReference, DocumentSnapshot, QueryDocumentSnapshot, OrderByDirection, WhereFilterOp, Query, QuerySnapshot, DocumentChangeType, CollectionReference, FieldValue, FieldPath, Timestamp, v1beta1, v1, FirebaseFirestore

23 declare namespace FirebaseFirestore {
   ~~~~~~~

  node_modules/firebase-admin/node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1
    23 declare namespace FirebaseFirestore {
       ~~~~~~~
    Conflicts are in this file.

node_modules/@google-cloud/firestore/types/firestore.d.ts:104:5 - error TS2374: Duplicate string index signature.

104     [key: string]: any; // Accept other properties, such as GRPC settings.
        ~~~~~~~~~~~~~~~~~~~

node_modules/firebase-admin/node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: DocumentData, UpdateData, Firestore, GeoPoint, Transaction, WriteBatch, WriteResult, DocumentReference, DocumentSnapshot, QueryDocumentSnapshot, OrderByDirection, WhereFilterOp, Query, QuerySnapshot, DocumentChangeType, CollectionReference, FieldValue, FieldPath, Timestamp, v1beta1, v1, FirebaseFirestore

23 declare namespace FirebaseFirestore {
   ~~~~~~~

  node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1
    23 declare namespace FirebaseFirestore {
       ~~~~~~~
    Conflicts are in this file.

Found 3 errors.
schmidt-sebastian commented 5 years ago

@lookfirst Hi! Thanks for your report. It looks like you are importing the types twice. Node should only pull in one version, but you might have outsmarted it somehow. We are not able to reproduce this issue locally, but all your errors could be explained by a double import.

If you are not able to solve this issue directly, we can probably take a look if you come up with a small reproducible example.

lookfirst commented 5 years ago

Sorry, I forgot to include my dependencies.

The @googlee-cloud/firestore dependency was included/used for the WhereFilterOp type. Removing that and changing the dependency to what the IDE suggested, import WhereFilterOp = firebase.firestore.WhereFilterOp; solved the issue.

Apologies for the waste of time and hope this helps someone else in the future who searches for it.

  "dependencies": {
    "@google-cloud/firestore": "*",
    "apollo": "*",
    "apollo-datasource": "*",
    "apollo-server-cloud-functions": "*",
    "apollo-server-core": "*",
    "cors": "*",
    "express": "*",
    "firebase": "*",
    "firebase-admin": "*",
    "firebase-functions": "*",
    "graphql": "*",
    "graphql-scalars": "*",
    "lodash": "*",
    "tslib": "*"
  },
  "devDependencies": {
    "@babel/core": "*",
    "@babel/preset-typescript": "*",
    "@graphql-codegen/cli": "*",
    "@graphql-codegen/introspection": "*",
    "@graphql-codegen/typescript": "*",
    "@graphql-codegen/typescript-document-nodes": "*",
    "@graphql-codegen/typescript-operations": "*",
    "@graphql-codegen/typescript-react-apollo": "*",
    "@graphql-codegen/typescript-resolvers": "*",
    "@types/cors": "*",
    "@types/lodash": "*",
    "@types/mocha": "*",
    "assert": "*",
    "graphql-tag": "*",
    "mocha": "*",
    "ts-node": "*",
    "tslint": "*",
    "typescript": "*"
  },
dhc86 commented 4 years ago

My editor was not be able to import OrderByDirection when working with firestore Cannot find name 'OrderByDirection' A solution for this is to import it manually as import { OrderByDirection } from '@firebase/firestore-types';

schmidt-sebastian commented 4 years ago

Note that @firebase/firestore-types is for @firebase/firestore. @google-cloud/firestore publishes its types along with the sources:

import { OrderByDirection } from '@google-cloud/firestore';