Webpack,枪,无法解析文件等,枪需要无法解析模块' fs'

时间:2016-07-27 03:30:40

标签: webpack gun

我正在使用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是枪的依赖吗?

更新
为了删除尽可能多的其他变量,我将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 }

2 个答案:

答案 0 :(得分:3)

这是一个枪祸,枪支队今天早上纠正了它。纠正错误并在我的项目中更新了枪后,我仍然遇到了与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中以使用带有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

答案 1 :(得分:1)

目前,在浏览器中你应该:

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

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

将来,我们会尝试并要求(' gun')自动检测环境,而不是自动包含仅限NodeJS的代码(如fs,websockets,http,等)