gpt4 book ai didi

node.js - "Error: Cannot find module"当使用 browserify 将 socket.io 依赖项与 --node 标志捆绑在一起时

转载 作者:搜寻专家 更新时间:2023-10-31 23:12:34 28 4
gpt4 key购买 nike

我正在尝试使用 browserify 将我的服务器端代码捆绑到一个 JS 文件中。所以我要跑

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 的版本已经超出了这个版本,我也已经尝试按照建议从源代码重建 Node ,但无济于事。

知道是什么导致了这个错误吗?

最佳答案

我遇到了同样的问题,我首先遇到了 bufferutil 的错误,然后是 utf-8-validate,但是根据这个 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.

关于node.js - "Error: Cannot find module"当使用 browserify 将 socket.io 依赖项与 --node 标志捆绑在一起时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30475215/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com