You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What went wrong?
start with sls invoke local --function some-function --watch
when change the code, it recompiles the code, but it still seems invoke the old compiled result
What did you expect should have happened?
It should run the latest compiled result just as what the documentation says.
It seems that Webpack 4 changed something with its watch mode. This comment #279 (comment) also points to that because for @stormit-vn it looks like the issue with watch happens with serverless-offline too.
This should be investigated, to see what exactly changed on Webpack's side, so that we can implement a proper fix.
Just to be completely sure. Can you try with serverless-webpack 5.0.0 and Webpack 3, to see if it is really a change in Webpack 4 that triggers the problem? If yes, we should put "Webpack 4" into the issue subject.
Further question: Did you set the new Webpack mode option to "development" for local invocations in your webpack.config? This enables debug functionality for the built output.
It seems that sls invoke local -f some-function --watch does not work for all of the combinations.
But it do work with sls offline start --watch, by "work" I mean when send a http request to the endpoint, it will response with the latest code ("good" changes to "good1").
The problem might be due to the require cache. Invoke local requires our handler and we do not terminate the Serverless process when running in watch mode. On a watch trigger, invoke local is executed again - and fetches our module under test from the require cache.
A solution would be to make sure that the invocation fetches a fresh module from disk.
@crysislinux Can you check with #351 if that works for you? I did some local tests and it seems that the handler is now loaded again correctly after a watch compile.
Activity
crysislinux commentedon Mar 15, 2018
I used to use --watch with
sls offline start --watch. It worked. This time I don't have a http event, so it's invoked directly, but it does not work.HyperBrain commentedon Mar 15, 2018
@crysislinux Thanks for reporting 👍
It seems that Webpack 4 changed something with its watch mode. This comment #279 (comment) also points to that because for @stormit-vn it looks like the issue with watch happens with serverless-offline too.
This should be investigated, to see what exactly changed on Webpack's side, so that we can implement a proper fix.
HyperBrain commentedon Mar 15, 2018
Just to be completely sure. Can you try with serverless-webpack 5.0.0 and Webpack 3, to see if it is really a change in Webpack 4 that triggers the problem? If yes, we should put "Webpack 4" into the issue subject.
HyperBrain commentedon Mar 15, 2018
Further question: Did you set the new Webpack mode option to "development" for local invocations in your webpack.config? This enables debug functionality for the built output.
crysislinux commentedon Mar 16, 2018
@HyperBrain Thanks for the quick response.
I tried with the following combinations
It seems that
sls invoke local -f some-function --watchdoes not work for all of the combinations.But it do work with

sls offline start --watch, by "work" I mean when send a http request to the endpoint, it will response with the latest code ("good" changes to "good1").And yes, I have this in webpack.config.js
HyperBrain commentedon Mar 16, 2018
Ok. Then it looks like a general issue restricted to
invoke local --watch. This is a bug then and has to be fixed.[-]--watch is not working[/-][+]invoke local --watch is not working[/+]HyperBrain commentedon Mar 17, 2018
The problem might be due to the require cache.
Invoke localrequires our handler and we do not terminate the Serverless process when running in watch mode. On a watch trigger,invoke localis executed again - and fetches our module under test from the require cache.A solution would be to make sure that the invocation fetches a fresh module from disk.
HyperBrain commentedon Mar 17, 2018
The code of the second answer here would make it possible to remove the old cached module and let the next invocation start freshly.
https://stackoverflow.com/questions/9210542/node-js-require-cache-possible-to-invalidate
HyperBrain commentedon Mar 20, 2018
@crysislinux Can you check with #351 if that works for you? I did some local tests and it seems that the handler is now loaded again correctly after a watch compile.
crysislinux commentedon Mar 22, 2018
@HyperBrain I am really sorry that I provide some misunderstanding information. I tried again and found that the bug happens only when
I tried your fix, it magically fix this problem anyway 😃