“错误:找不到模块”使用browserify将带有--node标志的socket.io依赖项捆绑在一起时 [英] "Error: Cannot find module" when using browserify to bundle a socket.io dependency with --node flag

查看:142
本文介绍了“错误:找不到模块”使用browserify将带有--node标志的socket.io依赖项捆绑在一起时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用browserify将我的服务器端代码捆绑到一个JS文件中。因此,我正在运行

I'm trying to use browserify to bundle my server side code into a single JS file. Hence I'm running

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 标志,它也可以正常工作。

The only offending line seems to be the require "socket.io". When I remove it the bundling works fine. It also works fine if I remove the --node flag.

缺失模块似乎在那里当我使用

The "missing" module appears to be there when I check the directory with

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 版本已经超出了该范围,我也已经尝试按照推荐的方法从源代码重建节点,但无济于事。

Some googling led me to this https://github.com/websockets/ws/issues/25. But that seems to be referring to an old version of ws. The version of ws in the module is already beyond that and I've also already tried rebuilding node from source as recommended but to no avail.

任何想法仍然可能导致此错误吗?

Any idea what could still be causing this error?

推荐答案

我遇到了同样的问题,我首先使用 bufferutil 出错,然后使用 utf-8-validate 出错,但是根据以下 Readme.md ,您需要根据需要使用-save 选项。希望这可以帮助。

I run into the same problem and I have error first with bufferutil then with utf-8-validate, but according to this Readme.md, you need to install them as requirements with --save options. Hope this helps.


有2个可选模块可以与ws模块一起安装。这些模块是二进制插件,可以改善某些操作,但由于它们是二进制插件,因此它们需要编译,如果主机系统上未安装c ++编译器,则编译可能会失败。

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 :改进了内部缓冲区操作,可以更快地处理屏蔽的WebSocket帧和常规缓冲区操作。

  • 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 :该规范要求验证无效的UTF-8字符,有些这些验证无法在JavaScript中完成,因此需要二进制插件。在大多数情况下,您将已经出于安全目的验证收到的输入,从而导致双重验证。但是,如果您希望100%符合规格并快速验证UTF-8,则必须使用此模块。

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.

这篇关于“错误:找不到模块”使用browserify将带有--node标志的socket.io依赖项捆绑在一起时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆