immobiliare / dats

📈 Minimalistic zero-dependencies statsd client for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing dns dependency

jajvisser opened this issue · comments

After installing and running in NextJS i get the following error on startup

../../node_modules/@immobiliarelabs/dats/dist/dns-cache.js:3:0
Module not found: Can't resolve 'dns'

Import trace for requested module:
../../node_modules/@immobiliarelabs/dats/dist/socket.js
../../node_modules/@immobiliarelabs/dats/dist/index.js

Hi @jajvisser 👋

dns is part of the Node.js standard library, if you want to use this package in Next.js you'll have to use it only on the server-side, eg: getServerSideProps

Hi, thanks for pointing me in the right direction.

The problem lies a bit deeper, the package is always included in the build to the frontend. Bable always includes it in the build. Only using it in getServerSideProps won't work.

I'm currently looking at excluding the package from the frontend build.

webpack: (config, { isServer, webpack }) => {
    if (!isServer) {
      config.resolve.fallback.dgram = false
      config.resolve.fallback.dns = false
      config.resolve.fallback.net = false
      config.resolve.fallback.tls = false
    }
    return config
  },

The dependencies seem to be working now with this configuration. But now i hit this error

error - ../node_modules/@immobiliarelabs/dats/dist/index.js (39:0) @ <unknown>
TypeError: Right-hand side of 'instanceof' is not an object

Yes, my solution above works