2015-05-27 57 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.

相关问题