New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoke local --watch is not working #349

Closed
crysislinux opened this Issue Mar 15, 2018 · 10 comments

Comments

Projects
None yet
2 participants
@crysislinux
Copy link

crysislinux commented Mar 15, 2018

This is a Bug Report

Description

  • 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.

  • What was the config you used?

service: some-service

plugins:
  - serverless-webpack
  - serverless-offline

custom:
  webpack:
    webpackIncludeModules: true

package:
  individually: true

provider:
  name: aws
  runtime: nodejs6.10
  stage: dev
  region: us-east-2

functions:
  some-function:
    handler: some-function/handler.handler
  • What stacktrace or error message from your provider did you see?
    No errors, the output is like this
    image

the second time it should output 5 instead of 6 because the code has changed.

Similar or dependent issue(s):

Additional Data

  • Serverless-Webpack Version you're using: 5.1.0
  • Webpack version you're using: 4.1.1
  • Serverless Framework Version you're using: 1.26.1
  • Operating System: macOs High Sierra 10.13.3
  • ***Stack Trace (if available)***:
@crysislinux

This comment has been minimized.

Copy link
Author

crysislinux commented 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 HyperBrain added the bug label Mar 15, 2018

@HyperBrain

This comment has been minimized.

Copy link
Member

HyperBrain commented 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

This comment has been minimized.

Copy link
Member

HyperBrain commented 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

This comment has been minimized.

Copy link
Member

HyperBrain commented 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.

mode: slsw.lib.webpack.isLocal ? "development" : "production"
@crysislinux

This comment has been minimized.

Copy link
Author

crysislinux commented Mar 16, 2018

@HyperBrain Thanks for the quick response.

I tried with the following combinations

  1. serverless-webpack 5.1.0 webpack 3
  2. serverless-webpack 5.1.0 webpack 4
  3. serverless-webpack 4 webpack 3

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").
image

And yes, I have this in webpack.config.js

mode: slsw.lib.webpack.isLocal ? "development" : "production"
@HyperBrain

This comment has been minimized.

Copy link
Member

HyperBrain commented 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.

@HyperBrain HyperBrain changed the title --watch is not working invoke local --watch is not working Mar 16, 2018

@HyperBrain

This comment has been minimized.

Copy link
Member

HyperBrain commented Mar 17, 2018

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.

@HyperBrain

This comment has been minimized.

Copy link
Member

HyperBrain commented 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

This comment has been minimized.

Copy link
Member

HyperBrain commented 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

This comment has been minimized.

Copy link
Author

crysislinux commented 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

package:
  individually: true  #enable this

I tried your fix, it magically fix this problem anyway 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment