2016-07-27 62 views
1

我正在與gundb電子應用程序。在所有其他工作後,我做了一個npm install --save gun。它完成了這個警告:Webpack,槍,無法解決文件等,槍要求無法解決模塊'FS'

npm WARN optional Skipping failed optional dependency /chokidar/fsevents: 
npm WARN notsup Not compatible with your operating system or architecture: [email protected] 

當我嘗試:

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槍npm的依賴?

UPDATE
要刪除許多其它變量可能,我減少了我的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 } 
+0

這fsevent警告很正常。他們沒有關係。 –

+0

這個問題也可能對其他Webpack/GUN錯誤有幫助(對於那些從Google點擊這個問題的人,但這不是正確的問題):http://stackoverflow.com/questions/39001582/running-gunjs-with -reactjs-and-webpack-throws-reference-error-in-console/39003291#39003291 – marknadal

回答

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 
+0

太棒了!很高興聽到我們推動的解決方案解決了主要問題。希望最終我們也可以讓這些最後幾個煩人的WARNING/ERROR消息消失。感謝您的回答,非常感謝! – marknadal

+0

由於這是@marknadal和朋友正在處理的已知問題,因此我繼續使用'stats:{warnings:false}'作爲減少噪音的骯髒解決方案。 – aleksblago

+0

@aleksblago哦,這是什麼幫助/解決了這個問題呢?我要添加關於require('gun/gun')的另一個答案; – marknadal

1

現在,在瀏覽器中,你應該:

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

解決您的問題。或者使用腳本標記,它在全局範圍內導出Gun。

在未來,我們會努力和有需要(「槍」)自動檢測環境,而不是自動包含唯一的NodeJS代碼(如fs,的WebSockets,HTTP等)