Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript errors in node_modules package with "export * as" syntax

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!

like image 526
Niels Kersic Avatar asked Aug 18 '20 23:08

Niels Kersic


People also ask

How do I export a ts module?

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.

Can we export type in TypeScript?

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.

How do you use export classes in TypeScript?

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.

What is import and export in TypeScript?

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.


Video Answer


1 Answers

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.

like image 171
Faraji Anderson Avatar answered Oct 16 '22 06:10

Faraji Anderson