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

Getting “Module not found” error when trying to use the Google APIs Node.js client #691

Closed
jacklaplante opened this issue Dec 29, 2016 · 2 comments
Assignees
Labels

Comments

@jacklaplante
Copy link

jacklaplante commented Dec 29, 2016

I'm trying to use the Google API Node.js client on a new React Web app. Here's my package.json:

{
  "name": "onboarding",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-scripts": "0.8.4"
  },
  "dependencies": {
    "googleapis": "^15.1.0",
    "react": "^15.4.1",
    "react-dom": "^15.4.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

When I try and access the API in App.js with:

var google = require('googleapis');

It won't compile and gives me:

Failed to compile.

Error in ./~/google-auth-library/lib/auth/googleauth.js
Module not found: 'child_process' in /home/jack/onboarding/node_modules/google-auth-library/lib/auth

 @ ./~/google-auth-library/lib/auth/googleauth.js 21:11-35

Error in ./~/googleapis/lib/generator.js
Module not found: 'swig' in /home/jack/onboarding/node_modules/googleapis/lib

 @ ./~/googleapis/lib/generator.js 21:11-26

Error in ./~/googleapis/lib/generator.js
Module not found: 'js-beautify' in /home/jack/onboarding/node_modules/googleapis/lib

 @ ./~/googleapis/lib/generator.js 22:15-37

I can get rid of the errors fr js-beautify and swig by manually adding them to the dependencies but this doesn't work for child_process. Either way I feel like I'm doing something wrong here. Should the var google = require('googleapis'); not be inside the react App.js code? Any advice would be appreciated.

@jacklaplante
Copy link
Author

I believe the issue was because I was calling the API from the frontend

@jmdobry
Copy link
Contributor

jmdobry commented Dec 29, 2016

Yeah, this library is Node.js-only, meant for server-side use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants