繁体   English   中英

找不到模块:无法解析“/Users/Austin/node_modules/pg/lib”中的“dns”

[英]Module not found: Can't resolve 'dns' in '/Users/Austin/node_modules/pg/lib'

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'

我很难理解这个错误信息。 我正在使用 next.js 并尝试创建不同的网页。 我将启动该程序,运行 npm run dev,它首先会给我以下信息:

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

然后给我这个错误。 这个错误是什么意思? 我在网上找到了不同的答案,但到目前为止都没有奏效。

我遇到了同样的问题。 该消息不是很有帮助,但它意味着您正在尝试在客户端上运行 node.js/服务器端代码。 例如,我的问题是在我的前端页面组件之一中导入我的数据库连接文件。 在客户端应用程序上,我导入了试图连接到 db 的db.js ,但该 db 连接需要 node.js 原生的dns模块。 浏览器无法执行,然后抛出错误。 这是一个容易陷入的陷阱,因为在 Next.js 应用程序中,前端和后端代码之间的界限是模糊的。

该文档可能对您的案例有用https://nextjs.org/docs/messages/module-not-found

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM