2015-05-27 55 views
4

「錯誤:無法找到模塊」我試圖使用browserify捆綁我的服務器端代碼到一個單一的JS文件。因此,我跑當使用browserify捆綁socket.io依賴關係與--node標誌

browserify --node -t coffeeify source/server.js.coffee -o deployment/server.js 

但我發現了以下錯誤

Error: Cannot find module '../build/Release/bufferutil' from '/My/Project/Path/node_modules/socket.io/node_modules/engine.io/node_modules/ws/lib' 

唯一出錯的行似乎是require "socket.io"。當我刪除它捆綁工作正常。如果我刪除--node標誌,它也可以正常工作。

「丟失」的模塊會出現在那裏當我檢查目錄與

ls node_modules/socket.io/node_modules/engine.io/node_modules/ws/build/Release/ 

我看到

.deps/   bufferutil.node* linker.lock  obj.target/  validation.node* 

一些谷歌搜索使我這個https://github.com/websockets/ws/issues/25。但這似乎是指舊版本ws。模塊中ws的版本已經超出了這個範圍,我也已經嘗試過從源代碼重建節點,但無濟於事。

任何想法仍然可能導致此錯誤?

+0

我認爲'--node'是問題所在。 [Here](https://github.com/substack/node-browserify#usage)你可以看到,它是'--no-builtins','--no-commondir'的別名,並且設置了' - -INSERT-全球vars'。我認爲刪除'--no-builtins'(或/和'--no-commondir')應該可以解決你的問題。 – marcel

+0

問題是我想要的。我試圖創建一個包在服務器上運行。不帶'--node'標誌運行它會導致創建的包發生錯誤,因爲它正確無法找到'window' – fynyky

回答

3

我遇到同樣的問題,我有錯誤先用utf-8-validatebufferutil然後,但根據本Readme.md,你需要將它們安裝與--save選項的要求。希望這可以幫助。

There are 2 optional modules that can be installed along side with the ws module. These modules are binary addons which improve certain operations, but as they are binary addons they require compilation which can fail if no c++ compiler is installed on the host system.

  • npm install --save bufferutil : Improves internal buffer operations which allows for faster processing of masked WebSocket frames and general buffer operations.

  • npm install --save utf-8-validate : The specification requires validation of invalid UTF-8 chars, some of these validations could not be done in JavaScript hence the need for a binary addon. In most cases you will already be validating the input that you receive for security purposes leading to double validation. But if you want to be 100% spec-conforming and have fast validation of UTF-8 then this module is a must.

相關問題