【问题标题】:Can't use core nodejs module with browserify (dgram)无法将核心 nodejs 模块与 browserify(dgram)一起使用
【发布时间】:2016-05-08 03:17:53
【问题描述】:

节点-v => v5.5.0

commande => "watchify src/js/app.js --extension=.jsx -t [ babelify --presets [ es2015 react stage-0 ] ] -o public/js/bundle .js -dv",

版本: "浏览": "^12.0.1", “监视”:“^3.6.1”

错误控制台 app.js:42 Uncaught TypeError: Dgram.createSocket is not a function

我在 app.js 中的代码:

var PORT = 33333;
var HOST = '127.0.0.1';

var Dgram = require('dgram');
var message = new Buffer('My KungFu is not good :(');

var client = Dgram.createSocket('udp4');
client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {
   if (err) throw err;
   console.log('UDP message sent to ' + HOST +':'+ PORT);
   client.close();
});

【问题讨论】:

    标签: node.js browserify


    【解决方案1】:

    dgram 不能在客户端与 browserify 一起使用。

    browserify 只支持 node 核心模块的一个子集:

    在需要时获取节点核心库事件、流、路径、url、assert、buffer、util、querystring、http、vm 和 crypto 的浏览器版本

    source.

    还请查看this answerthat one,了解 UDP 在浏览器中的不可用性。

    【讨论】:

    • 好的,谢谢。现在,我找到了如何制作别名或其他东西。
    猜你喜欢
    • 2020-10-01
    • 2022-06-21
    • 2015-08-30
    • 1970-01-01
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-11
    相关资源
    最近更新 更多