admin管理员组

文章数量:1278793

An issue with next.js

  Module not found: Can't resolve 'dns' in '/Users/Austin/node_modules/pg/lib'
    Could not find files for /index in .next/build-manifest.json
    ModuleNotFoundError: Module not found: Error: Can't resolve 'dns' in '/Users/Austin/node_modules/pg/lib'

I'm having a hard time understanding this error message. I'm using next.js and trying to create different webpages. I'll start the program, running npm run dev, and it will give me this at first:

[ wait ]  starting the development server ...
[ info ]  waiting on http://localhost:3000 ...
[ ready ] piled successfully - ready on http://localhost:3000
[ wait ]  piling ...
[ ready ] piled successfully - ready on http://localhost:3000

and following that give me this error. What does this error mean? I've found different answers online and none of them have worked so far.

An issue with next.js

  Module not found: Can't resolve 'dns' in '/Users/Austin/node_modules/pg/lib'
    Could not find files for /index in .next/build-manifest.json
    ModuleNotFoundError: Module not found: Error: Can't resolve 'dns' in '/Users/Austin/node_modules/pg/lib'

I'm having a hard time understanding this error message. I'm using next.js and trying to create different webpages. I'll start the program, running npm run dev, and it will give me this at first:

[ wait ]  starting the development server ...
[ info ]  waiting on http://localhost:3000 ...
[ ready ] piled successfully - ready on http://localhost:3000
[ wait ]  piling ...
[ ready ] piled successfully - ready on http://localhost:3000

and following that give me this error. What does this error mean? I've found different answers online and none of them have worked so far.

Share Improve this question edited Aug 18, 2021 at 20:36 brc-dd 13k3 gold badges59 silver badges86 bronze badges asked Dec 4, 2019 at 16:30 user5491053user5491053 1
  • I guess showing some code would be helpful, as your index page, next.js config. – Evgeny Timoshenko Commented Dec 5, 2019 at 10:15
Add a ment  | 

1 Answer 1

Reset to default 14

I've run into the same issue. The message is not super helpful but it means you are trying to run node.js/server side code on the client. For example, my problem was importing my db connection file in one of my front end page ponents. On the client app, I import db.js that is trying to connect to a db, but that db connection requires the dns module which is native to node.js. The browser can't execute and then throws the error. This is an easy trap to fall into because the line between frontend and backend code is blurry in Next.js apps.

本文标签: javascriptModule not found Can39t resolve 39dns39 in 39UsersAustinnodemodulespglib39Stack Overflow