Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Can't resolve 'dns' #53

Closed
okaysuper opened this issue Mar 15, 2021 · 3 comments
Closed

Can't resolve 'dns' #53

okaysuper opened this issue Mar 15, 2021 · 3 comments

Comments

@okaysuper
Copy link

Hello,

I'm trying to use @vercel/fetch in nextjs on the serverside
Whatever I try I always have the same error:

./node_modules/@zeit/dns-cached-resolve/lib/dns-resolve.js:6:0
Module not found: Can't resolve 'dns'

Am I doing something wrong?

Thanks for your help.

@nsmith7989
Copy link

@okaysuper I had the same problem trying to use this in nextjs. I think the problem is that dns is built into node, but isn't available in the browser. You need to make sure you're using this server side only.

I have a file that is both server and client side so my solution is something like:

function getFetch() {
  if (typeof window === 'undefined') {
    const createFetch = require('@vercel/fetch');
    return createFetch();
  }
  return window.fetch;
}

Alternatively if you're in nextjs and doing something in getStaticProps or getServerSideProps if you only use this package there nextjs will take care of not including this in the client bundle and causing errors.

@okaysuper
Copy link
Author

@nsmith7989 thanks for your answer.
As far as I know I'm using it only on the server side but you are probably right. @vercel/fetch somehow ended up in the client bundle otherwise I wouldn't get this error. I'll investigate further or try your solution if I need it on the client. Thanks!

@Ethan-Arrowood
Copy link
Collaborator

Thank you for the report. We are archiving this project; you can read more details here: #83

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants