0

I'm using node-ssdp to detect an IOT device connected to the network. Both server code and client code works fine with a sample node project. My client app is in angular-electron with webpack as the module bundler. I installed node-ssdp in the angular project with

npm install node-ssdp --save

node-ssdp gets installed successfully. But then webpack fails with following errors.

ERROR in ./~/node-ssdp/test/lib/server.js
Module not found: Error: Can't resolve 'chai' in 'J:\fyp\desktop-client\node_modules\node-ssdp\test\lib'
 @ ./~/node-ssdp/test/lib/server.js 3:13-28
 @ ./~/node-ssdp ^.*server$
 @ ./~/node-ssdp/index.js
 @ ./src/app/providers/pd.service.ts
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in ./~/node-ssdp/test/lib/client.js
Module not found: Error: Can't resolve 'chai' in 'J:\fyp\desktop-client\node_modules\node-ssdp\test\lib'
 @ ./~/node-ssdp/test/lib/client.js 4:13-28
 @ ./~/node-ssdp ^.*client$
 @ ./~/node-ssdp/index.js
 @ ./src/app/providers/pd.service.ts
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in ./~/node-ssdp/test/helper.js
Module not found: Error: Can't resolve 'sinon' in 'J:\fyp\desktop-client\node_modules\node-ssdp\test'
 @ ./~/node-ssdp/test/helper.js 1:12-28
 @ ./~/node-ssdp/test/lib/server.js
 @ ./~/node-ssdp ^.*server$
 @ ./~/node-ssdp/index.js
 @ ./src/app/providers/pd.service.ts
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

ERROR in ./~/node-ssdp/test/helper.js
Module not found: Error: Can't resolve 'dgram' in 'J:\fyp\desktop-client\node_modules\node-ssdp\test'
 @ ./~/node-ssdp/test/helper.js 3:12-28
 @ ./~/node-ssdp/test/lib/server.js
 @ ./~/node-ssdp ^.*server$
 @ ./~/node-ssdp/index.js
 @ ./src/app/providers/pd.service.ts
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

I tried installing the above missing chai, sinon, dgram dependencies manually.chai and sinon errors got eliminated but not dgram.

I did tried several times and wasted few hours on this. But I was not succeeded. Can anyone suggest a solution please?

Dulaj Atapattu
  • 448
  • 6
  • 23
  • What [target](https://webpack.js.org/configuration/target/) are you using in your Webpack configuration? – robertklep Jul 28 '17 at 17:39
  • @robertklep I'm not familiar with webpack. Can you please tell me how to find it? I'm building for electron anyway. – Dulaj Atapattu Jul 28 '17 at 18:21
  • Does your project have a file called `webpack.config.js`? The target should be set in there. If it isn't in there, Webpack will default to the `web` target, which in your case isn't the right one. – robertklep Jul 28 '17 at 18:55
  • Yes it's there. This is it https://hastebin.com/lowojuhika.js – Dulaj Atapattu Jul 28 '17 at 19:14
  • Yes `webpack.config.js` there. But target has not been set. This is `webpack.config.js` https://hastebin.com/lowojuhika.js . What is the target to be set for an electron app? Is it `electron-main` or `electron-renderer`? – Dulaj Atapattu Jul 28 '17 at 19:22
  • Not sure, but I guess it'd be easy to try both and see if that solves your issue (although looking at the config, you may also need to remove some entries in the `node` property, all the way down) – robertklep Jul 28 '17 at 19:56
  • @robertklep tried both for target. But didn't work. I think this is some incompatibility issue of node-ssdp with webpack. – Dulaj Atapattu Jul 29 '17 at 08:12
  • Why didn't it work? Did you get errors? Did you remove any entries from the `node` property in the configuration file? – robertklep Jul 29 '17 at 09:38
  • Yes I got the same error. I didn't remove any property from configuration file. – Dulaj Atapattu Jul 29 '17 at 11:34

1 Answers1

0

If anyone is still looking at this, dgram was deprecated by npm, but was adopted by node. Here's the source code for dgram https://github.com/nodejs/node/blob/v20.5.1/lib/dgram.js.

Anon
  • 1