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

Typescript transpilation fails #1548

Closed
sonicoder86 opened this issue May 4, 2022 · 7 comments
Closed

Typescript transpilation fails #1548

sonicoder86 opened this issue May 4, 2022 · 7 comments
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@sonicoder86
Copy link

sonicoder86 commented May 4, 2022

After upgrading the library from 2.19.0 to 2.19.3 the Typescript transpilation started to fail with the following error message

node_modules/@google-cloud/pubsub/build/protos/protos.d.ts:15:23 - error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.

15 import * as Long from "long";
                         ~~~~~~

node_modules/google-gax/build/protos/iam_service.d.ts:17:23 - error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.

17 import * as Long from 'long';
                         ~~~~~~

node_modules/google-gax/build/protos/operations.d.ts:17:23 - error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.

17 import * as Long from 'long';
                         ~~~~~~


Found 3 errors in 3 files.

Environment details

  • OS: macOS Monterey 12.3.1
  • Node.js version: 14.17.4
  • npm version: 6.14.14
  • @google-cloud/pubsub version: 2.19.3

Steps to reproduce

  1. Install typescript and @google-cloud/pubsub latest
import { PubSub, Topic } from '@google-cloud/pubsub';
console.log(PubSub, Topic);
  1. Transpile the above code with latest Typescript

Created an example repository, just have to clone, install and run npm run build.
Setting the flag esModuleInterop to true doesn't solve the issue.

@sonicoder86 sonicoder86 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels May 4, 2022
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/nodejs-pubsub API. label May 4, 2022
@angishen
Copy link

angishen commented May 4, 2022

I'm also getting these compile errors after upgrading to 2.19.3. However, I continue getting the errors even when I revert back to 2.19.0 and as far back as 2.18.4. This is with TS version 4.6.4.

On versions 2.18.3 and earlier, I get a different compile error:

node_modules/@google-cloud/pubsub/build/src/message-stream.d.ts:83:5 - error TS2416: Property 'destroy' in type 'MessageStream' is not assignable to the same property in base type 'PassThrough'.
  Type '(error?: Error | null | undefined) => void' is not assignable to type '(error?: Error | undefined) => this'.
    Type 'void' is not assignable to type 'this'.
      'this' could be instantiated with an arbitrary type which could be unrelated to 'void'.

83     destroy(error?: Error | null): void;

@angishen
Copy link

angishen commented May 5, 2022

I'm able to get rid of the compile errors if I manually go into the listed files in my node_modules and change the erroring imports into default imports:

import Long from "long"

@sonicoder86
Copy link
Author

Maybe hardcoding the Long version to v4? dcodeIO/long.js#109

@sonicoder86
Copy link
Author

For a temporal solution, this worked in package.json:

"overrides": {
  "long": "4.0.0"
}

@feywind
Copy link
Collaborator

feywind commented May 5, 2022

Hmm, this looks like it might be related to the effort to update from Node 10. @bcoe ?

@stevanmilic
Copy link

@feywind
Copy link
Collaborator

feywind commented May 6, 2022

Ah right, it was probably related to this: grpc/grpc-node#2110

@feywind feywind closed this as completed May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants