I'm working on a Typescript NodeJS project that uses multiple Google Cloud client libraries. I want to use ES6 imports for these client libraries so I can use Intellisense in VS Code. However, when I use ES6 imports I get the following issues when trying to compile Typescript:
TS1005: 'from' expected. 119 export * as protobufMinimal from 'protobufjs/minimal'; ~~ node_modules/google-gax/build/src/fallback.d.ts:119:13 - error TS1005: ';' expected. 119 export * as protobufMinimal from 'protobufjs/minimal'; ~~~~~~~~~~~~~~~ node_modules/google-gax/build/src/fallback.d.ts:119:29 - error TS1005: ';' expected. 119 export * as protobufMinimal from 'protobufjs/minimal'; ~~~~ node_modules/google-gax/build/src/fallback.d.ts:119:34 - error TS1005: ';' expected. 119 export * as protobufMinimal from 'protobufjs/minimal'; ~~~~~~~~~~~~~~~~~~~~ node_modules/google-gax/build/src/index.d.ts:47:10 - error TS1005: 'from' expected. 47 export * as protobufMinimal from 'protobufjs/minimal'; ~~ node_modules/google-gax/build/src/index.d.ts:47:13 - error TS1005: ';' expected. 47 export * as protobufMinimal from 'protobufjs/minimal'; ~~~~~~~~~~~~~~~ node_modules/google-gax/build/src/index.d.ts:47:29 - error TS1005: ';' expected. 47 export * as protobufMinimal from 'protobufjs/minimal'; ~~~~ node_modules/google-gax/build/src/index.d.ts:47:34 - error TS1005: ';' expected. 47 export * as protobufMinimal from 'protobufjs/minimal'; ~~~~~~~~~~~~~~~~~~~~ Found 8 errors. ```
Are there any changes I need to make to my tsconfig
to fix this?
Thanks!
The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum. When exporting a module using export = , TypeScript-specific import module = require("module") must be used to import the module.
Use a named export to export a type in TypeScript, e.g. export type Person = {} . The exported type can be imported by using a named import as import {Person} from './another-file' . You can have as many named exports as necessary in a single file.
Use named exports to export multiple classes in TypeScript, e.g. export class A {} and export class B {} . The exported classes can be imported by using a named import as import {A, B} from './another-file' . You can have as many named exports as necessary in a file.
A module can be created using the keyword export and a module can be used in another module using the keyword import . In TypeScript, files containing a top-level export or import are considered modules. For example, we can make the above files as modules as below. file1.ts.
If you're seeing this in your GCloud builds the fix in my case was updating Typescript from 3.7.2 to 4.1.3 - from my understanding any version 3.9+ should work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With