我在ReactJS Webpack应用程序中使用https://www.npmjs.com/package/googleapis。它确实警告说它是Alpha版本,所以可以预料到会有问题,这就是我遇到的问题。npm install googleapis --save
已安装googleapis
好的,
在我的package.json中添加了"googleapis": "^2.0.2"
,但是当我运行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
Node 版本v0.12.1
在此先感谢您的帮助!
最佳答案
我没有一个有效的答案,但我也在寻找一个答案。您在GitHub上的dmk12吗?如果没有,请看一下这个问题:
https://github.com/google/google-api-nodejs-client/issues/403
问题的一部分似乎是库中有一行var Endpoint = require(endpointPath);
必须对其进行评估,因为endpointPath
是一个变量。不幸的是,该问题表明他们可能不会更改此行为,因为这会使他们的代码更灵活。一个人(也许是您?)建议通过在<script>
中通过index.html
标记加载API来解决此问题,但这对我们不起作用---我的团队,我想从服务器端代码中使用API。
寻找答案的过程仍在继续。