I'm trying to upgrade to serverless-webpack 3 from 1 and running into this:
[ 'Error: Cannot find module \'/Users/user/Source/my-project/functions/.webpack/src/handlers/icon\'',
'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 Object.createHandler (/Users/user/Source/my-project/functions/node_modules/serverless-offline/src/functionHelper.js:35:21)',
'at handler (/Users/user/Source/my-project/functions/node_modules/serverless-offline/src/index.js:499:40)',
'at Object.internals.handler (/Users/user/Source/my-project/functions/node_modules/hapi/lib/handler.js:96:36)',
'at request._protect.run (/Users/user/Source/my-project/functions/node_modules/hapi/lib/handler.js:30:23)',
'at internals.Protect.run (/Users/user/Source/my-project/functions/node_modules/hapi/lib/protect.js:64:5)',
'at exports.execute (/Users/user/Source/my-project/functions/node_modules/hapi/lib/handler.js:24:22)',
'at each (/Users/user/Source/my-project/functions/node_modules/hapi/lib/request.js:384:16)',
'at iterate (/Users/user/Source/my-project/functions/node_modules/items/lib/index.js:36:13)',
'at done (/Users/user/Source/my-project/functions/node_modules/items/lib/index.js:28:25)',
'at internals.Auth._authenticate (/Users/user/Source/my-project/functions/node_modules/hapi/lib/auth.js:210:16)',
'at internals.Auth.authenticate (/Users/user/Source/my-project/functions/node_modules/hapi/lib/auth.js:202:17)',
'at each (/Users/user/Source/my-project/functions/node_modules/hapi/lib/request.js:384:16)',
'at iterate (/Users/user/Source/my-project/functions/node_modules/items/lib/index.js:36:13)',
'at done (/Users/user/Source/my-project/functions/node_modules/items/lib/index.js:28:25)',
'at internals.state (/Users/user/Source/my-project/functions/node_modules/hapi/lib/route.js:357:16)',
'at each (/Users/user/Source/my-project/functions/node_modules/hapi/lib/request.js:384:16)',
'at iterate (/Users/user/Source/my-project/functions/node_modules/items/lib/index.js:36:13)',
'at Object.exports.serial (/Users/user/Source/my-project/functions/node_modules/items/lib/index.js:39:9)',
'at internals.Request._lifecycle (/Users/user/Source/my-project/functions/node_modules/hapi/lib/request.js:387:11)',
'at internals.Request._execute (/Users/user/Source/my-project/functions/node_modules/hapi/lib/request.js:302:21)',
'at Domain.request._protect.enter (/Users/user/Source/my-project/functions/node_modules/hapi/lib/connection.js:261:25)',
'at Domain.run (domain.js:221:14)',
'at internals.Protect.enter (/Users/user/Source/my-project/functions/node_modules/hapi/lib/protect.js:80:17)',
'at Server.<anonymous> (/Users/user/Source/my-project/functions/node_modules/hapi/lib/connection.js:259:30)',
'at emitTwo (events.js:106:13)',
'at Server.emit (events.js:191:7)',
'at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:548:12)' ]
It looks like webpack is actually building to .webpack/service/src/handlers/icon. I don't know where the service directory is coming from.
Hi @aaronjensen , thanks for using the plugin 馃槃 .
There have been a lot of changes from 1.x to 3.x - most noticably the auto-configuration. Your problem here is, that you have to switch to entry point auto-resolution and it will work.
To do that, add the following to your webpack config as mentioned in the README:
// webpack config
const slsw = require('serverless.webpack');
...
module.exports = {
...
entry: slsw.lib.entries,
...
output: {
...
filename: '[name].js',
...
}
};
and make sure that your handler definitions in your serverless.yml point to the handlers correctly, in case they are located in subfolders, as in this example:
# serverless.yml
functions:
myfunc:
handler: src/handlers/myfunc.handle
As last step, remove any --location switch from the serverless offline commandline. Serverless-webpack will set it automatically to the correct output folder.
Then everything should work and you also can switch to individual packaging now. This will lead to packages, that only contain the needed and referenced modules.
FYI: webpack is now a peer dependency and has to be installed in the projects dev dependencies. I'd go for webpack 3.6.0 which works very well.
To your question: As the plugin now fully supports auto-configuration and individual packaging, the _internal_ temporary build directory structure has been changed, but the plugin will take care that all other plugins will point to it correctly. Additionally serverless invoke local [--watch] is now fully supported. For more information see the README.
Thanks, it looks like dropping --location was necessary. I've got it working now. Cheers!
Glad to hear that it works now 馃憤
Use serverless plugin install --name serverless-webpack
I update "severless-offline-sqs" version and works for me, try:
"serverless-offline": "^6.9.0",
"serverless-offline-sqs": "4.1.1",
Most helpful comment
Hi @aaronjensen , thanks for using the plugin 馃槃 .
There have been a lot of changes from 1.x to 3.x - most noticably the auto-configuration. Your problem here is, that you have to switch to entry point auto-resolution and it will work.
To do that, add the following to your webpack config as mentioned in the README:
and make sure that your handler definitions in your
serverless.ymlpoint to the handlers correctly, in case they are located in subfolders, as in this example:As last step, remove any
--locationswitch from theserverless offlinecommandline. Serverless-webpack will set it automatically to the correct output folder.Then everything should work and you also can switch to individual packaging now. This will lead to packages, that only contain the needed and referenced modules.
FYI: webpack is now a peer dependency and has to be installed in the projects dev dependencies. I'd go for webpack 3.6.0 which works very well.
To your question: As the plugin now fully supports auto-configuration and individual packaging, the _internal_ temporary build directory structure has been changed, but the plugin will take care that all other plugins will point to it correctly. Additionally
serverless invoke local [--watch]is now fully supported. For more information see the README.