MylesBorins / node-osc

Open Sound Control protocol library for Node.js
GNU Lesser General Public License v3.0
435 stars 72 forks source link

cannot resolve 'dgram' error #80

Closed kyeshmz closed 2 years ago

kyeshmz commented 2 years ago

Hi I get a can't resolve 'dgram' error, which doesn't really let up as NPM is holding dgram. Is there a work around this or way to install this into a nextjs project?

Here is the steps to recreate node v 16.10

yarn create next-app --template typescript
yarn add node-osc
kyeshmz commented 2 years ago

Also does not seem to work with vite, as I get a


node_modules/node-osc/lib/Client.mjs:1:9: ERROR: No matching export in "browser-external:dgram" for import "createSocket"
node_modules/node-osc/lib/Server.mjs:1:9:```
kyeshmz commented 2 years ago

I suspect it is something to do with webpack, as per here. This fix worked for the other package https://github.com/adzialocha/osc-js/issues/50

MylesBorins commented 2 years ago

@kyeshmz dgram is a node.js internal package. When we drop support for Node.js 12 in april we can be more explicit about this by importing it as import dgram from 'node:dgram'.

If you want to not polyfill here you need to make an update to your webpack config. If you are trying to run this in the browser you are not going to be able to as this package only supports udp for the transport layer and as such is Node.js only.

Depending on the kind of setup you are planning to do you can use web sockets to communicate between a browser client and a node.js server to proxy actions from the browser to be sent as OSC messages. Please take a look at this starter project which has an example full stack app to send slider data from the browser as OSC messages by way of web socket -> osc message (using socket.io and node-osc).

I'm going to go ahead and close this as I don't believe there is anything actionable we can do here in node-osc but please feel free to ask more questions or let me know if I've missed anything

Polyterative commented 2 years ago

Took me a while to realize I won't be able tu run this in the browser. Any alternative to node-osc which has strong typescript support? I'm trying to work in Angular