Can't use core nodejs module with browserify (dgram)

node -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",

versions: "browserify": "^12.0.1", "watchify": "^3.6.1"

error console app.js:42 Uncaught TypeError: Dgram.createSocket is not a function

my code in 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();
});

dgram cannot be used client-side with browserify.

Only a subset of node's core modules are supported by browserify:

Get browser versions of the node core libraries events, stream, path, url, assert, buffer, util, querystring, http, vm, and crypto when you require() them

source.

Have also a look at this answer and that one regarding UDP's unavailability inside the browser.

链接地址: http://www.djcxy.com/p/32940.html

上一篇: 如何使用React和Webpack设置Babel 6阶段0

下一篇: 不能使用具有browserify(dgram)的核心nodejs模块