1

我正在使用 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上。fsevent 是 gun npm 的依赖项吗?

更新
为了尽可能多地删除其他变量,我将我的 package.json 文件缩减为只有电子......消除了 webpack 和其他依赖项可能存在的问题。我还删除了我的 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 }
4

2 回答 2

3

那是一个枪支错误,枪支团队今天早上纠正了它。在纠正错误并在项目中更新 gun 后,我仍然遇到与 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.config.js 才能将 gun 与 webpack 一起使用:

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-07-27T16:33:13.643 回答
1

现在,在浏览器中你应该:

var Gun = require('gun/gun');

解决您的问题。或者使用一个脚本标签,它可以全局导出 Gun。

将来,我们将尝试使用 require('gun') 自动检测环境,而不是自动包含仅 NodeJS 的代码(例如fs,websockets,http 等)

于 2016-10-13T04:46:29.073 回答