I have created a web application using Next JS which runs fine with npm run dev
. But when I tried to run it in production mode with npm run build
, I get the errors given below. I have tried changing the permissions of node_modules
directory, running npm install
, trying to update NodeJS and NPM however nothing works. I could not find much about this on the internet as well.
> 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
I have finally found the solution and my problem has been fixed. This error was showing up because there were some serverless-mysql
DB files in the pages
directory and the error disappeared after I moved those non-page files outside of the pages directory.
Source: https://github.com/vercel/next.js/issues/9768#issuecomment-663835978
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.