【问题标题】:Next JS Cannot resolve fs when running npm run buildNext JS 在运行 npm run build 时无法解析 fs
【发布时间】:2020-12-03 23:51:10
【问题描述】:

我使用 Next JS 创建了一个 Web 应用程序,它在 npm run dev 上运行良好。但是当我尝试使用npm run build 在生产模式下运行它时,我得到了下面给出的错误。我尝试更改node_modules 目录的权限,运行npm install,尝试更新NodeJS 和NPM,但没有任何效果。我在互联网上也找不到太多关于此的内容。

> html@0.1.0 build /var/www/app/html
> next build

Creating an optimized production build

Failed to compile.

./node_modules/mysql/lib/protocol/sequences/Query.js
Module not found: Can't resolve 'fs' in '/var/www/app/html/node_modules/mysql/lib/protocol/sequences'


> Build error occurred
Error: > Build failed because of webpack errors
    at build (/var/www/app/html/node_modules/next/dist/build/index.js:13:917)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! html@0.1.0 build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the html@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-08-14T04_54_38_531Z-debug.log

【问题讨论】:

标签: node.js npm next.js


【解决方案1】:

我终于找到了解决方案,我的问题也得到了解决。出现此错误是因为 pages 目录中有一些 serverless-mysql DB 文件,并且在我将这些非页面文件移到 pages 目录之外后,该错误消失了。

来源:https://github.com/vercel/next.js/issues/9768#issuecomment-663835978

【讨论】:

    猜你喜欢
    • 2019-07-05
    • 2019-11-15
    • 2017-10-05
    • 2020-01-07
    • 2021-03-03
    • 2021-11-28
    • 2023-01-09
    • 2020-09-14
    • 2022-06-16
    相关资源
    最近更新 更多