获取"未找到模块"尝试使用Google API Node.js客户端时出错

时间:2016-12-29 17:25:55

标签: javascript node.js reactjs google-api-nodejs-client

我试图在新的React Web应用上使用Google API Node.js client。 这是我的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"
  }
}

当我尝试使用以下命令访问App.js中的API时

var google = require('googleapis');

它不会编译并给我:

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

我可以通过手动将它们添加到依赖项来消除fr js-beautifyswig错误,但这对child_process不起作用。无论哪种方式,我觉得我在这里做错了什么。 var google = require('googleapis');是否应该在反应App.js代码中?任何建议将不胜感激。

1 个答案:

答案 0 :(得分:0)

我认为我遇到问题的原因是因为我试图从前端访问API。