[英]error - ./node_modules/web3-eth-contract/node_modules/web3-providers-http/lib/index.js:26:0 Module not found: Can't resolve 'http'
[英]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 应用程序中,前端和后端代码之间的界限是模糊的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.