When doing a serverless build, the build fails with ModuleNotFoundError: Module not found: Error: Can't resolve 'aws-sdk'
I've trace it down to the bcrypt module being used in an api function. I assume since this module a server function running on the server side it should work. Running a normal server build does not produce any errors.
Here is the full error:
> next build
info - Creating an optimized production build
Failed to compile.
ModuleNotFoundError: Module not found: Error: Can't resolve 'aws-sdk' in '/home/mike/test/nextjs-serverless-build/node_modules/node-pre-gyp/lib'
> Build error occurred
Error: > Build failed because of webpack errors
at build (/home/mike/test/nextjs-serverless-build/node_modules/next/dist/build/index.js:15:918)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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! /home/mike/.npm/_logs/2020-08-27T03_25_35_982Z-debug.log
I've created a repo from a barebones create-next-app example. The only change is pages/api/hello.js uses the bcrypt module and the next.config.js is set to serverless.
https://github.com/mikecao/nextjs-serverless-build
Should not produce an error.
I got the same error with serverless build, it works fine with normal build.
@mikecao Check this issue: #4940
@dakshshah96 That issue was due to people using node-only modules on the client side. That's why I created the repo example to show it still fails in the simplest case.
Most helpful comment
@dakshshah96 That issue was due to people using node-only modules on the client side. That's why I created the repo example to show it still fails in the simplest case.