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然后我就得到了这个错误。这个错误是什么意思?我在网上找到了不同的答案,但到目前为止都没有奏效。
发布于 2020-08-04 12:39:20
我也遇到过同样的问题。该消息不是非常有用,但它意味着您正尝试在客户端运行node.js/服务器端代码。例如,我的问题是在我的一个前端页面组件中导入我的数据库连接文件。在客户端应用程序上,我导入了试图连接到数据库的db.js,但该数据库连接需要node.js原生的dns模块。浏览器无法执行,然后抛出错误。这是一个很容易陷入的陷阱,因为在Next.js应用程序中,前端和后端代码之间的界限是模糊的。
https://stackoverflow.com/questions/59180601
复制相似问题