我正在用gundb开发一个电子应用程序。在完成其他工作之后,我做了一个npm install --save gun。它在此警告之后完成:
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.14当我试图:
require('gun');
var endpoints;
var gun = Gun(endpoints);我得到了一长串自那以后我无法犯的错误。它们首先是:
.../node_modules/fs doesn't exist
.../node_modules/fs.webpack.js doesn't exist
.../node_modules/fs.web.js doesn't exist
.../node_modules/fs.js doesn't exist
.../node_modules/fs.json doesn't exist以下问题无法解决:
@ ./~/gun/lib/file.js 14:10-23
@ ./~/gun/lib/wsp.js 61:39-52
@ ./~/ws/lib/WebSocketServer.js 15:10-2
@ ./~/options/lib/options.js 6:9-2
@ ./~/aws-sdk/lib/api_loader.js 1:9-22
@ ./~/aws-sdk/lib/services.js 1:9-22我在Linux上。是对枪支npm的依赖吗?
更新
为了尽可能地删除其他变量,我将我的package.json文件简化为只存在webpack和其他依赖项可能出现的electron....eliminating问题。我还删除了我的node_modules并做了一个新的npm install & npm install gun。
这揭示了一个更有用的错误:
Uncaught ReferenceError: Gun is not defined gun.js:1470其中指出:
if(typeof window !== "undefined"){ Gun.request = request }
if(typeof module !== "undefined" && module.exports){ module.exports.request = request }发布于 2016-07-27 16:33:13
那是个枪虫今早枪队纠正了。在错误被纠正,我在我的项目中更新了枪后,我仍然遇到了与webpack捆绑在一起的问题:
WARNING in ./~/ws/lib/BufferUtil.js
Module not found: Error: Cannot resolve module 'bufferutil' in /node_modules/ws/lib
@ ./~/ws/lib/BufferUtil.js 10:19-40
WARNING in ./~/ws/lib/Validation.js
Module not found: Error: Cannot resolve module 'utf-8-validate' in /node_modules/ws/lib
@ ./~/ws/lib/Validation.js 10:19-44
WARNING in ./~/formidable/lib/incoming_form.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
@ ./~/formidable/lib/incoming_form.js 1:43-50
WARNING in ./~/formidable/lib/file.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
@ ./~/formidable/lib/file.js 1:43-50
WARNING in ./~/formidable/lib/json_parser.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
@ ./~/formidable/lib/json_parser.js 1:43-50
WARNING in ./~/formidable/lib/querystring_parser.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
@ ./~/formidable/lib/querystring_parser.js 1:43-50
WARNING in ./~/aws-sdk/lib/util.js
Critical dependencies:
40:30-45 the request of a dependency is an expression
43:11-53 the request of a dependency is an expression
@ ./~/aws-sdk/lib/util.js 40:30-45 43:11-53
WARNING in ./~/aws-sdk/lib/api_loader.js
Critical dependencies:
13:15-59 the request of a dependency is an expression
104:12-46 the request of a dependency is an expression
108:21-58 the request of a dependency is an expression
114:18-52 the request of a dependency is an expression
@ ./~/aws-sdk/lib/api_loader.js 13:15-59 104:12-46 108:21-58 114:18-52为了和webpack一起使用枪,我不得不在我的webpack.config.js中添加以下内容:
var webpack = require('webpack');
module.exports = {
devtool: "source-map",
target: "node",
....
module: {
noParse: [/aws-sdk/],
....
plugins: [
new webpack.DefinePlugin({ "global.GENTLY": false })
]
....在这一点上,尽管我在bash中仍然有以下错误,但一切都在正常工作:
WARNING in ./~/ws/lib/BufferUtil.js
Module not found: Error: Cannot resolve module 'bufferutil' in /node_modules/ws/lib
@ ./~/ws/lib/BufferUtil.js 10:19-40
WARNING in ./~/ws/lib/Validation.js
Module not found: Error: Cannot resolve module 'utf-8-validate' in /node_modules/ws/lib
@ ./~/ws/lib/Validation.js 10:19-44发布于 2016-10-13 04:46:29
现在,在浏览器中,您应该:
var Gun = require('gun/gun');来解决你的问题。或者使用脚本标记,它可以向全局导出Gun。
在未来,我们将尝试并要求(“gun”)自动检测环境,而不是自动-只包含NodeJS代码(如fs、websockets、http等)。
https://stackoverflow.com/questions/38603238
复制相似问题