Various modules fail from node package - am I out of luck?

Hello.

I apologize for asking a question that has probably been answered a lot here but I have very little experience in the JS/Node world and am just starting to look at k6 as well.

I was trying to create a test suite that would test my IoT backend that uses the CoAP protocol (the simple explanation is that it’s binary HTTP on top of UDP). I found only one JS library that can do CoAP (GitHub - coapjs/node-coap: CoAP - Node.js style) and after following the instructions here I ended up trying to run npm run bundle and got a bunch of “Module not found” errors.

I did see the notification in the documentation that NodeJS packages would possibly not work, especially it seems lower level modules (os, fs, net, etc) and that seems to be exactly my problem:

❯ npm run bundle |grep "Can't resolve"
Module not found: Error: Can't resolve 'net' in '/Users/stefan.freyr/work/pocs/coap/k6/node_modules/coap/dist'
Module not found: Error: Can't resolve 'crypto' in '/Users/stefan.freyr/work/pocs/coap/k6/node_modules/coap/dist/lib'
Module not found: Error: Can't resolve 'dgram' in '/Users/stefan.freyr/work/pocs/coap/k6/node_modules/coap/dist/lib'
Module not found: Error: Can't resolve 'crypto' in '/Users/stefan.freyr/work/pocs/coap/k6/node_modules/coap/dist/lib'
Module not found: Error: Can't resolve 'stream' in '/Users/stefan.freyr/work/pocs/coap/k6/node_modules/coap/dist/lib'
Module not found: Error: Can't resolve 'net' in '/Users/stefan.freyr/work/pocs/coap/k6/node_modules/coap/dist/lib'
Module not found: Error: Can't resolve 'dgram' in '/Users/stefan.freyr/work/pocs/coap/k6/node_modules/coap/dist/lib'
Module not found: Error: Can't resolve 'os' in '/Users/stefan.freyr/work/pocs/coap/k6/node_modules/coap/dist/lib'

My question is simply: Am I completely out of luck here? Is there any way for me to get this to work with k6?

I’ve tried to find a “pure” coap library that I could use but the node-coap one is the only thing I’ve found so far.

Hi @StFS !

Welcome to the community forums! :wave:

Unfortunately, I can only confirm your conjectures. At the moment of posting my answer, and as you’ve already seen in Modules, neither os nor fs modules won’t work. Which means that everything that is built on top of them won’t work.

The other way to get support for that protocol is implementing this as the xk6-extension JavaScript Extensions. For instance it could be a wrapper around one of the existing go libraries for the CoAP). But that requires some golang knowledge :frowning_face:

Cheers!

1 Like