question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sls invoke local with webpack v3.0.0 throws "module not found"

See original GitHub issue

This is a (Bug Report / Feature Proposal)

Bug report

Description

Installed v3.0.0 to try out invoke local. The previous version works fine on the same repo using sls webpack... I can see that SLS builds with webpack but then throws the error about missing module (see stack trace).

Additional Data

  • Serverless-Webpack Version you’re using: 3.0.0
  • Webpack version you’re using: 3.5.0
  • Serverless Framework Version you’re using: 1.19.0
  • Operating System: Windows 10
  • Stack Trace (if available):
{ Error: Cannot find module './.webpack/service/handler'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at AwsInvokeLocal.invokeLocalNodeJs (./npm/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:156:33)
    at AwsInvokeLocal.invokeLocal (./npm/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:114:19)
    at AwsInvokeLocal.tryCatcher (./npm/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (./npm/node_modules/serverless/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (./npm/node_modules/serverless/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (./npm/node_modules/serverless/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (./npm/node_modules/serverless/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (./npm/node_modules/serverless/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (./npm/node_modules/serverless/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (./npm/node_modules/serverless/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:637:20)
    at tryOnImmediate (timers.js:610:5)
    at processImmediate [as _immediateCallback] (timers.js:582:5) code: 'MODULE_NOT_FOUND' }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
QAnderscommented, Aug 8, 2017

Thanks! Changing the entry works fine!

1reaction
HyperBraincommented, Aug 8, 2017

Can you try to use automatic entry resolution, so that the plugin tries to determine the handler? Please change the webpack.conf.js as follows:

const slsw = require('serverless-webpack');
module.exports = {
  ...
  entry: slsw.lib.entries,
  ...
};

Additionally you should use Webpack 2.x.x or Webpack 3.x.x (as a dev dependency of your project). You have to use module.rules instead of modules.loaders for the newer webpack versions (the sample below also uses babel-preset-node6). Webpack 1.x.x might not work very well.

...
	module: {
		rules: [
			{
				// Process ES6 with Babel.
				test: /\.js$/,
				use: [
					{
						loader: "babel-loader",
						options: {
							presets: [ "node6" ],
							plugins: []
						}
					}
				],
			}
		]
	}
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Serverless Webpack - Serverless Framework: Plugins
A Serverless Framework plugin to build your lambda functions with Webpack. ... Support of serverless invoke local and serverless invoke local --watch ...
Read more >
Serverless Framework with AWS Lambda error "Cannot find ...
I'm trying to use the Serverless Framework to create a Lambda function that uses open weather NPM module. However ...
Read more >
Serverless Webpack in Lambda Simplified 101 - Learn | Hevo
When you specify a module in both the forceInclude and forceExclude arrays, the exclude array wins, and the module is not packaged. Local...
Read more >
serverless-offline/community - Gitter
Hey folks. Just wondering if sls-offline supports sls v3 as it is now, or not. I'm getting hit with Detected unrecognized CLI options:...
Read more >
Troubleshoot deployment issues in Lambda
General: Cannot find, cannot load, unable to import, class not found, no such file or directory ... Error: Handler 'handler' missing on module...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found