Serverless build fails with: ModuleNotFoundError: Module not found: Error: Can't resolve 'aws-sdk'
See original GitHub issueBug 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! test@0.1.0 build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@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! /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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:9
Top Results From Across the Web
Serverless Framework with AWS Lambda error "Cannot find ...
I have the same problem with serverless framework to deploy multiple lambda functions. I fixed by the following steps.
Read more >Nextjs deploy error after installing remark-prism package
Serverless build fails with: ModuleNotFoundError: Module not found: Error: Can't resolve 'aws-sdk' The cause is that, the dependency needs ...
Read more >Serverless Webpack - Serverless Framework: Plugins
A Serverless Framework plugin to build your lambda functions with Webpack. ... All settings are optional and will be set to reasonable defaults...
Read more >Troubleshoot deployment issues in Lambda
General: Cannot find, cannot load, unable to import, class not found, no such file or directory. Error: Cannot find module 'function'. Error: cannot...
Read more >How do I resolve a 'module not found' error? - Vercel
The 'module not found' error is a syntax error that appears when the static import statement cannot find the file at the declared...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just a +1: You can expect this error to occur when creating a serverless build with say, a NextJS + MDX app that uses
remark-prism
'canvas'
, injsdom
yarn.lock
, you can see thatjsdom
is used byremark-prism
@lednhatkhanh
I got it to work with adding a custom webpack config for next.js and adding externals