Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue while using import { google } from 'googleapis' in Angular 6 Application #1270

Open
shiven80 opened this issue Aug 2, 2018 · 11 comments
Open

Comments

@shiven80
Copy link

@shiven80 shiven80 commented Aug 2, 2018

Hi,

I have installed "npm install googleapis@32.0.0" in my Angular 6 application to do service-to-service-authentication for Google Analytics API. I am following below article to achieve this.

https://libraries.io/npm/googleapis#service-to-service-authentication

However when I am including import { google } from 'googleapis'; or like const { OAuth2Client } = require('google-auth-library'); in .ts file in service class while ng build I am getting multiple errors

ERROR in ./node_modules/gtoken/node_modules/mime/index.js
ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'child_process' in
ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js

Thanks!

@JustinBeckwith

This comment has been minimized.

Copy link
Collaborator

@JustinBeckwith JustinBeckwith commented Aug 12, 2018

Greetings! Is it possible you're trying to use this npm module from the client? Are you bundling this via webpack or something? That's not currently supported, but is on it's way over in googleapis/google-auth-library-nodejs#371.

@shiven80

This comment has been minimized.

Copy link
Author

@shiven80 shiven80 commented Aug 14, 2018

Hi Justin, I am using npm module from Angular 6 application. I am using CLI to build the package not webpack.

@donmahallem

This comment has been minimized.

Copy link

@donmahallem donmahallem commented Jan 24, 2019

@shiven80 the cli uses webpack but I do face the same problem when using it in a server application written in typescript.

@DrewMcArthur

This comment has been minimized.

Copy link

@DrewMcArthur DrewMcArthur commented Aug 17, 2019

Hi @JustinBeckwith, I'd like to bump this as I'm still getting import errors from compiling with tsc after installing via npm.

drew@local$ tsc
src/GoogleApiWrapper.ts:2:35 - error TS2307: Cannot find module 'googleapis'.

2 import { google, sheets_v4 } from 'googleapis';
                                    ~~~~~~~~~~~~

src/GoogleAuthWrapper.ts:9:24 - error TS2307: Cannot find module 'googleapis'.

9 import { google } from 'googleapis';
                         ~~~~~~~~~~~~

src/GoogleAuthWrapper.ts:11:30 - error TS2307: Cannot find module 'googleapis-common'.

11 import { OAuth2Client } from 'googleapis-common';
                                ~~~~~~~~~~~~~~~~~~~
@vmasek

This comment has been minimized.

Copy link

@vmasek vmasek commented Sep 8, 2019

Is there any ETA on this? I'd like to integrate this SDK in an Angular app

@JustinBeckwith

This comment has been minimized.

Copy link
Collaborator

@JustinBeckwith JustinBeckwith commented Sep 8, 2019

Nope, there is not sadly

@bcoe

This comment has been minimized.

Copy link
Contributor

@bcoe bcoe commented Sep 13, 2019

@vmasek @shiven80 you might be able to create a working module using web-pack, which you could then import into angular. To do so you would use configuration something like this, in tsconfig.js:

module.exports = {
    resolve: {
        extensions: ['.js'],
        alias: {
            fs: path.resolve(__dirname, 'src/mock-fs.js'),
            child_process: path.resolve(__dirname, 'src/mock/mock-child-process.js')
        }
    }
};

where modck-fs.js, mock-child-process.js, etc., are stubbed out Node.js APIs:

module.exports = {
  readFileSync () {}
}

With a bit of work I think you could build a workaround using this approach; unfortunately there's no ETA right now on when we'll be able to add first-class browser support to all our libraries.

@vmasek

This comment has been minimized.

Copy link

@vmasek vmasek commented Oct 25, 2019

I've created a blog post on how to integrate this SDK with Angular, thank you for your help @bcoe

https://blog.angularindepth.com/google-apis-with-angular-214fadb8fbc5

@bcoe

This comment has been minimized.

Copy link
Contributor

@bcoe bcoe commented Oct 25, 2019

@vmasek this is great 🎉 I'm going to reference the heck out of this article.

@bcoe

This comment has been minimized.

Copy link
Contributor

@bcoe bcoe commented Oct 25, 2019

@vmasek is your email on GitHub a good way to reach you with some feedback on your article?

@vmasek

This comment has been minimized.

Copy link

@vmasek vmasek commented Oct 25, 2019

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.