6

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! :)

5
  • 1
    On a side note, tsc has been deprecated for quite a while now Commented Feb 22, 2019 at 20:36
  • @NinoFiliu - I'm not using that module. tsc is a sym link from /usr/local/lib/node_modules/typescript/bin/tsc and it's typescript version 3.3.3 Commented Feb 22, 2019 at 20:49
  • Ah ok! I couldn't reproduce the issue. I'm trying again... Commented Feb 22, 2019 at 20:52
  • still can't reproduce the issue Commented Feb 22, 2019 at 20:56
  • @NinoFiliu - cloned and built your site, gives me all those errors Commented Feb 22, 2019 at 22:15

1 Answer 1

6

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.json and wait for them to be fixed.

Sign up to request clarification or add additional context in comments.

2 Comments

Although this works for now, I still think this is kind of a bandaid solution for me. The above commenter on my post appears to NOT have the same issue on their machine which makes me think something else is up even though I'm using the right version of typescript.
If you have a few minutes, you can go to his repo that's basically a carbon copy, git clone it and run it and see if you have the same issues as I if you'd like to verify.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.