Reputation: 3514
I am building an Angular2 app that is using Webpack for my build process. I would like to create a Google oauth login function in my app. And so I have installed the googleapi package from npm. But I'm running into some trouble importing this package into my app.
I'm trying import * from 'googleapi';
but this crashes the app with message:
Uncaught ReferenceError: require is not defined
This is my System.config:
System.config({
map: {
rxjs: 'node_modules/rxjs',
googleapis: 'node_modules/googleapis'
},
meta: {
googleapis: { format: 'commonjs' }
},
packages: {
app: {
format: 'register',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
System.import('app/contacts-app').then(null, console.error.bind(console));
How do I include this package in my app?
Upvotes: 1
Views: 765
Reputation: 667
There is now an ng-gapi
npm wrapper for googleapis functionality for Angular. This may support your requirements: https://www.npmjs.com/package/ng-gapi
Upvotes: 0
Reputation: 202138
I'm not sure that this library can be used within the browser since it relies on the google-auth-library
library that uses the request
one. The latter can only be used within Node applications...
There is a port of the request
library for the browser: https://www.npmjs.com/package/browser-request.
Regarding your error, perhaps you forgot to include SystemJS in your HTML file:
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script> <----
Upvotes: 1