serverless-webpack: V3: Unable to import module 'handler': Error
I often have this error and I never know where to look at to fix the issue. Is there a way/tool to have more information about the error ?
I have the SLS_DEBUG set to true but it doesn’t help.
Unable to import module 'handler': Error
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/var/task/handler.js:373:19)
at __webpack_require__ (/var/task/handler.js:20:30)
at Object.<anonymous> (/var/task/handler.js:53:19)
at __webpack_require__ (/var/task/handler.js:20:30)
at /var/task/handler.js:40:18
at Object.<anonymous> (/var/task/handler.js:43:10)
Thank you very much! Thierry
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 32
- Comments: 43 (11 by maintainers)
In my case, making sure that ALL required modules were actually in package.json solved the issue 😃
I just ran into this issue again, and it was caused by a dependency accidentally being added to
devDependencieswhen it should have been independencies.I had this issue until I discovered I was missing "babel-runtime"in
dependencies.I’m having the same issue. I can run the function locally with
$ serverless webpack invoke -f myFunction -p event.json. But when the function is deployed to AWS, every invocation fails:@dimitrovs’s solution of adding the following option worked for me.
Using
Also, I updated my answer as I just realized “babel-polyfill” belongs in
dependenciesnot indevDependencies.For anyone who casually skims the responses (like I did), the quick solution is to make sure everything you require is in your package.json under “dependencies”.
If you are still getting errors, check out dimitrovs’ issue.
@adamwilbert @hassankhan I seem to have fixed the issue I was having with webpack but modifying my webpack.config.js
Made the change of:
libraryTarget: 'commonjs2',tolibraryTarget: 'commonjs',as well as
You can see the Lambda working here:
https://kirhd1mpkb.execute-api.us-west-2.amazonaws.com/production/
Just having other issues now with API timeouts when registering or logging in a user. Will work on them next.
Well the problem is webpack 4.1.0 version. I updated all the packages first that also updated webpack to latest version. Back to webpack 3.11.0 and its solved. Maybe you should emphasise this more on the documentation @HyperBrain Edit: (Finally I just noticed Webpack 4 issue now at the top of issues list. Great, spent so much on this and it was obvious from the very beginning)
@Vadorequest I agree that a better message should be provided. Maybe the plugin could error out if a required dependency is detected that appears in devDependencies.
regarding your deps - babel-runtime and source-map-support are dependencies that are used at runtime and not build time, so they must be in the dependencies section.
For domain-manager, I don’t know if there are any runtime function in there.
Glad to here that it works now 😃 . Indeed setting
webpackIncludeModulesto false or omitting it completely will disable any module packaging.Maybe the default should be
true, even if not set, as this is the most likely case that users want to use.For reference, I experienced this issue because I used
baseUrlints-configbut forgot to includeNODE_PATHasenvvariables.I added
NODE_PATHas myenvvariable and resolved an issue.