Skip to content

dgram.createSocket is not a function #76

@DocCaliban

Description

@DocCaliban

I seem to be missing something, not sure if this is a bug or a documentation error.

I am running a React Typescript project and want to do a simple query.
My code is as follows

import makeMdns, { Options } from "multicast-dns";

  const options: Options = {
    loopback: false,
}
  const mdns = makeMdns(options);
  mdns.on('response', function(response) {
    console.log('got a response packet:', response)
  })
  
  mdns.on('query', function(query) {
    console.log('got a query packet:', query)
  })
  
  mdns.query('bob');

When the page renders, I immediately get the error TypeError: dgram.createSocket is not a function

push../node_modules/multicast-dns/index.js.module.exports
D:/Dev/pixelcade/node_modules/multicast-dns/index.js:25
  22 |   throw new Error('For IPv6 multicast you must specify `ip` and `interface`')
  23 | }
  24 | 
> 25 | var socket = opts.socket || dgram.createSocket({
     | ^  26 |   type: type,
  27 |   reuseAddr: opts.reuseAddr !== false,
  28 |   toString: function () {

I can verify that dgram is not installed in my node_modules, and adding it manually doesn't seem to work either.

As a side note; I am on windows and using YARN rather than NPM.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions