Getting "Module not found" error when trying to use the Google APIs Node.js client

1.7k views Asked by At

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.

1

There are 1 answers

0
Snubber On

I believe the reason I'm having issues is because I'm trying to access the API from the front-end.