在webpack上使用google-api-nodejs-client进行grunt构build时的错误

我在ReactJS Webpack应用程序中使用https://www.npmjs.com/package/googleapis 。 它有一个警告,这是一个alpha版本,所以问题是可以预料的,这是我所拥有的。

npm install googleapis --save已安装好的googleapis ,添加"googleapis": "^2.0.2"到我的package.json,但是当我运行grunt build我得到了以下警告(后面有很多我将要发布的错误请求,因为它是很多文字):

 WARNING in ./~/googleapis/apis/index.js Critical dependencies: 41:23-44 the request of a dependency is an expression @ ./~/googleapis/apis/index.js 41:23-44 WARNING in ./~/googleapis/~/request/~/hawk/~/hoek/lib/index.js Critical dependencies: 403:34-60 the request of a dependency is an expression @ ./~/googleapis/~/request/~/hawk/~/hoek/lib/index.js 403:34-60 

~/googleapis/apis/index.js的违规行是:

 var Endpoint = require(endpointPath); 

我得到的错误之一:

 ERROR in ./~/googleapis/~/request/~/hawk/~/hoek/lib/index.js Module not found: Error: Cannot resolve module 'fs' in /Users/dev/wwb-web-app/node_modules/googleapis/node_modules/request/node_modules/hawk/node_modules/hoek/lib @ ./~/googleapis/~/request/~/hawk/~/hoek/lib/index.js 3:9-22 

在我的React组件中需要googleapis的代码:

 var gapi = require('googleapis'); 

注意:可以根据要求提供组件中的其他代码,但我不认为这与这个问题有关。

我的package.json依赖关系:

 "dependencies": { "aws-sdk": "^2.0.21", "chalk": "^0.5.0", "crypto-js": "^3.1.2-5", "cryptojs": "^2.5.3", "envify": "^1.2.1", "fluxxor": "1.5.1", "googleapis": "^2.0.2", "imports-loader": "^0.6.3", "jquery": "~2.1.1", "moment": "^2.8.3", "react": "0.11.1", "react-bootstrap": "0.12.0", "react-router": "0.5.2", "react-router-bootstrap": "0.5.0" }, "devDependencies": { "connect-livereload": "^0.4.0", "css-loader": "^0.7.0", "es6-promise": "^1.0.0", "esrever": "^0.1.0", "grunt": "^0.4.5", "grunt-contrib-copy": "^0.5.0", "grunt-contrib-less": "~0.11.4", "grunt-contrib-uglify": "^0.7.0", "grunt-contrib-watch": "^0.6.1", "grunt-git": "^0.2.14", "grunt-gitinfo": "^0.1.6", "grunt-karma": "^0.8.3", "grunt-lesslint": "^1.1.13", "grunt-rsync": "^0.6.1", "grunt-ssh": "^0.11.2", "grunt-webpack": "^1.0.8", "jssha": "^1.5.0", "jsx-loader": "^0.10.2", "karma": "^0.12.17", "karma-chrome-launcher": "^0.1.7", "karma-coverage": "^0.2.7", "karma-jasmine": "^0.1.5", "karma-js-coverage": "^0.4.0", "karma-osx-reporter": "^0.1.0", "karma-phantomjs-launcher": "^0.1.4", "karma-sourcemap-loader": "^0.3.2", "karma-webpack": "^1.2.1", "load-grunt-tasks": "^0.6.0", "style-loader": "^0.6.4", "time-grunt": "^1.0.0", "webpack": "^1.4.15" } 

npm版本2.5.1

节点版本v0.12.1

提前感谢任何帮助!

我没有一个工作的答案,但也正在寻找一个。 你在GitHub上dmk12吗? 如果没有,请看看这个问题:

https://github.com/google/google-api-nodejs-client/issues/403

看起来问题的一部分是图书馆有一条线

var Endpoint = require(endpointPath);

必须对其进行评估,因为endpointPath是一个variables。 不幸的是,这个问题说他们可能不会改变这种行为,因为它使得他们的代码更加灵活。 一个人(或许你?)build议通过在index.html通过<script>标签加载API来解决这个问题,但是这对我们不起作用—我的团队和我想从服务器端代码中使用API 。

寻找答案仍在继续。

正如项目团队的评论所阐明的那样, google-api-nodejs-client项目不支持浏览器的使用。 它仅用于服务器端。

为了解决如何将Google API与React Webpack应用程序一起使用的广泛问题,基于RedMail的Redmail邮件客户端提供了一个示例。

在NuclearMail的入口点, index.html加载Webpack包,然后加载一个handleGoogleClientLoadcallback的Google API加载:

 <script src="app.js"></script> <script src="https://apis.google.com/js/client.js?onload=handleGoogleClientLoad"></script> 
Interesting Posts