我试图在新的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-beautify
和swig
错误,但这对child_process
不起作用。无论哪种方式,我觉得我在这里做错了什么。 var google = require('googleapis');
是否应该在反应App.js代码中?任何建议将不胜感激。
答案 0 :(得分:0)
我认为我遇到问题的原因是因为我试图从前端访问API。