Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript Google API compilation errors

I'm using Typescript, tslint and Google APIs but there's issues compiling in typescript to javascript and I'm not sure why and for some reason I can't find anything specific online about this problem. Google searches don't render good results. I can't find a good example of how your tsconfig should be setup with this library also. So I'm coming here.

I'm running into lots of "Cannot find type definition file" and "Cannot find module" errors when I run tsc.

My file is literally just this line:

import {google} from 'googleapis'

That's it.

When I run tsc it gives me these errors:

$ tsc
node_modules/gaxios/build/src/common.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.

1 /// <reference types="node" />
                        ~~~~

node_modules/gaxios/build/src/common.d.ts:3:23 - error TS2307: Cannot find module 'https'.

3 import { Agent } from 'https';
                        ~~~~~~~

node_modules/google-auth-library/build/src/auth/authclient.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/auth/authclient.d.ts:17:30 - error TS2307: Cannot find module 'events'.

17 import { EventEmitter } from 'events';
                                ~~~~~~~~

node_modules/google-auth-library/build/src/auth/googleauth.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/auth/googleauth.d.ts:17:21 - error TS2307: Cannot find module 'fs'.

17 import * as fs from 'fs';
                       ~~~~

node_modules/google-auth-library/build/src/auth/googleauth.d.ts:19:25 - error TS2307: Cannot find module 'stream'.

19 import * as stream from 'stream';
                           ~~~~~~~~

node_modules/google-auth-library/build/src/auth/googleauth.d.ts:182:20 - error TS2503: Cannot find namespace 'NodeJS'.

182     _osPlatform(): NodeJS.Platform;
                       ~~~~~~

node_modules/google-auth-library/build/src/auth/jwtaccess.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/auth/jwtaccess.d.ts:17:25 - error TS2307: Cannot find module 'stream'.

17 import * as stream from 'stream';
                           ~~~~~~~~

node_modules/google-auth-library/build/src/auth/jwtclient.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/auth/jwtclient.d.ts:18:25 - error TS2307: Cannot find module 'stream'.

18 import * as stream from 'stream';
                           ~~~~~~~~

node_modules/google-auth-library/build/src/auth/refreshclient.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/auth/refreshclient.d.ts:17:25 - error TS2307: Cannot find module 'stream'.

17 import * as stream from 'stream';
                           ~~~~~~~~

node_modules/google-auth-library/build/src/crypto/crypto.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/crypto/crypto.d.ts:32:60 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.

32     verify(pubkey: string | JwkCertificate, data: string | Buffer, signature: string): Promise<boolean>;

My tsconfig file is:

    {
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "esModuleInterop": true,
    "noImplicitAny": false,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "app",
    "baseUrl": "./app",
    "paths": {
      "*": [
        "node_modules/*"
      ]
    }
  },
  "include": [
    "src/**/*"
  ]
}

My package dependencies are:

  "dependencies": {
    "googleapis": "^37.2.0",
    "mysql": "^2.16.0",
    "typescript": "^3.3.3333"
  },
  "devDependencies": {
    "nodemon": "^1.18.10",
    "tslint": "^5.12.1"
  }

I'm not using the tsc node module (which is deprecated), I'm using typescript v3.3.3

Help would be appreciated! :)

like image 700
Paul Carlton Avatar asked Feb 22 '19 20:02

Paul Carlton


1 Answers

Type errors in 3rd party libraries typings can easily be avoided by either submitting a pull request OR turning on skipLibCheck: true in your tsconfig and wait for them to be fixed.

Hope this helps.

like image 57
Shanon Jackson Avatar answered Nov 04 '22 18:11

Shanon Jackson