Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 cannot find module 'dgram'

I have installed a template Ionic 2 application and want to add the NPM package bonjour

After installing and including the package in my component like this:

var Bonjour = require('bonjour');
var bonjour = new Bonjour();

The application won't run stating 'cannot find module dgram'

The application has both the bonjour package and bonjour types installed.

The problem

The application can't find the module dgram which is located in the @types/node file. The project is running TS 2.4.2 and should not need any references to the @types, this should be picked up automatically.

What have I tried

I tried including the @types folder anyway in multiple ways, by setting typeroots or types in the ts.config.json file. This didn't change anything.

I tried specifying types :

"types": ["node", "bonjour"]

I tried reinstalling all node modules and clearing the cache

I tried including a reference path in my component above the require statement:

/// <reference path="node_modules/@types/node/index.d.ts" />

var Bonjour = require('bonjour');
var bonjour = new Bonjour();

This all did not help. Any ideas on how to make my application load this module properly?

like image 236
WJM Avatar asked Aug 01 '17 23:08

WJM


1 Answers

The package Bonjour has a DatagramPlugin which require dgram to function properly. In Ionic 2 this package is not available. The solution is to use the Native Zeroconf package as an alternative.

like image 200
WJM Avatar answered Sep 27 '22 23:09

WJM