Nodejs-pubsub: Node project wont build because of TS dependencies

Created on 29 Oct 2020  路  3Comments  路  Source: googleapis/nodejs-pubsub

Environment details

  • OS:
  • Node.js version: 10.15.1
  • npm version: 6.4.1
  • @google-cloud/pubsub version: 2.6.0

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

pubsub question

Most helpful comment

@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.

All 3 comments

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

@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.

@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.

Was this page helpful?
0 / 5 - 0 ratings