googleapis / nodejs-pubsub

Node.js client for Google Cloud Pub/Sub: Ingest event streams from anywhere, at any scale, for simple, reliable, real-time stream analytics.
https://cloud.google.com/pubsub/
Apache License 2.0
517 stars 232 forks source link

Node project wont build because of TS dependencies #1143

Closed vongohren closed 1 year ago

vongohren commented 3 years ago

Environment details

Steps to reproduce

  1. For me, include the pubsub library into a monorepo with a mix of typescript and javasript package/project. With typescript version: 3.3.3
  2. Import the pubsub
  3. Compile
  4. See it fail

Extra information

diwala-api: $ tsc && yarn build-ssr
diwala-api: ../../node_modules/@google-cloud/pubsub/node_modules/google-gax/build/src/fallback.d.ts(119,10): error TS1005: 'from' expected.
diwala-api: ../../node_modules/@google-cloud/pubsub/node_modules/google-gax/build/src/fallback.d.ts(119,13): error TS1005: ';' expected.
diwala-api: ../../node_modules/@google-cloud/pubsub/node_modules/google-gax/build/src/fallback.d.ts(119,29): error TS1005: ';' expected.
diwala-api: ../../node_modules/@google-cloud/pubsub/node_modules/google-gax/build/src/fallback.d.ts(119,34): error TS1005: ';' expected.
diwala-api: ../../node_modules/@google-cloud/pubsub/node_modules/google-gax/build/src/index.d.ts(47,10): error TS1005: 'from' expected.
diwala-api: ../../node_modules/@google-cloud/pubsub/node_modules/google-gax/build/src/index.d.ts(47,13): error TS1005: ';' expected.
diwala-api: ../../node_modules/@google-cloud/pubsub/node_modules/google-gax/build/src/index.d.ts(47,29): error TS1005: ';' expected.
diwala-api: ../../node_modules/@google-cloud/pubsub/node_modules/google-gax/build/src/index.d.ts(47,34): error TS1005: ';' expected.
diwala-api: error Command failed with exit code 1.
diwala-api: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

That ts error Leads to this gooogle search: https://www.google.com/search?q=ts1005

I can solve this by using pubsub library version 1.7.3 instead

vongohren commented 3 years ago

I can confirm that if I increase my Typescript version, which was 3.3.3, to the latest 3 version, 3.9, this error goes away. But then it should be some dependency notice.

It might be related to these issues: https://github.com/googleapis/nodejs-pubsub/issues/1074 which leads to https://github.com/googleapis/nodejs-pubsub/pull/1079

But upgrading pubsub library, does not solve my other problem: https://github.com/googleapis/nodejs-pubsub/issues/1144

JustinBeckwith commented 3 years ago

@vongohren it's great that updating your version of TypeScript seemed to solve this problem. I think this is honestly a gap with TypeScript that we have no idea how to fix.

@bcoe another case of older versions of TypeScript giving us trouble. Throwing an idea out there - could we list typescript as an optionalDependency, and then rely on downstream consumers using --engines-strict to surface these kinds of errors? Otherwise, I honestly have no idea how we can ever what version of TypeScript our generated d.ts requires.

bcoe commented 3 years ago

@JustinBeckwith I think having it as an optional dependency would be a heavy-handed for our non-TypeScirpt users, as I believe this will attempt an install of the dep (and just not fail if for some reason the install fails).

We could perhaps add a warning that attempts to detect the locally installed TypeScript, and recommends updating if we find an incompatible version.

meredithslota commented 1 year ago

Closing this out as it appears that this happens with older versions of TypeScript that are now even older (3.3.3 is circa Feb 2019, we're up to 4.8.4 now) since this issue is ~2 years old. :) If this is still causing problems, please open a new issue!