So in my particular case, I'm using TypeScript and it appears the typings were misleading. The package web3-providers-ws
says that the following import should be valid:
import { WebsocketProvider } from "web3-providers-ws"
const provider = new WebsocketProvider("<host>", { ... })
It seems the typings lies a bit (or at least, there is something else that prevent it to work as expected).
I had to do the following to overcome the problem:
import WebsocketProvider from "web3-providers-ws"
// @ts-ignore It appears default export is required otherwise it throws 'WebsocketProvider is not a constructor error', the typings says otherwise but well ...
const provider = new WebsocketProvider("<host>", { ... })
I tried to play with various tsconfig.json
options around module and default imports, but did not succeed. Not sure what is not working yet, but at least I have a workaround.
Hopefully it helps someone else.