Next.js: Serverless build fails with: ModuleNotFoundError: Module not found: Error: Can't resolve 'aws-sdk'

Created on 27 Aug 2020  路  3Comments  路  Source: vercel/next.js

Bug report

Describe the bug

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

To Reproduce

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

Expected behavior

Should not produce an error.

System information

  • OS: Ubuntu 20.04
  • Version of Next.js: 9.5.2
  • Version of Node.js: 14.8.0
good first issue example

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rauchg picture rauchg  路  208Comments

acanimal picture acanimal  路  74Comments

poyiding picture poyiding  路  73Comments

Knaackee picture Knaackee  路  122Comments

Timer picture Timer  路  87Comments