juanjoDiaz/serverless-middleware

Error when using serverless-offline

Closed this issue ยท 7 comments

I'm on windows, I'm not putting the code since it's just an empty project with nothing more than copy/paste from the docs of serverless-middleware, so it's not remarkable special code

When using serverless-middleware with serverless offline there are some problems:

  • whenever I try to run the command serverless offline it would throw an error regarding the handler being an array, when this should be normal when using middlewares

    • "Solution": this previous problem solve when using serverless offline start as the starting command, but then another problem appears
  • followed the previous steps, now whenever I try to cancel the process in git bash or powershell I got the error:
    Error: ENOTEMPTY: directory not empty, rmdir 'C:\Users\ ... \.middleware'

    • "Solution": mark cleanFolder: false in the serverless.yml (option that I actually don't want)

Hi @xaeli

whenever I try to run the command serverless offline it would throw an error regarding the handler being an array, when this should be normal when using middlewares

Are you declaring the middleware plugin before the offline plugin? That is necessary for list of middlewares to be converted into a single handler which is use by serverless offline.

I will review the lifecycle events anyway.

followed the previous steps, now whenever I try to cancel the process in git bash or powershell I got the error:
Error: ENOTEMPTY: directory not empty, rmdir 'C:\Users\ ... .middleware'

I've never seen this. I'll need to check.

Could you share the versions of serverless and the plugins which you are using?

After double checking the docs from serverless-offline, the first issue is expected. Just poorly documented.
To use serverless offline with any other plugin, you nee to use the start command so it fires the lifecycle events (see https://github.com/dherault/serverless-offline#usage-with-serverless-dynamodb-local-and-serverless-webpack-plugin)

The second issue still needs to be resolved.

The second issue means that the .middleware folder is not being created.
If you are not getting errors, it probably wasn't needed which can happen if there are no functions actually using middlewares i.e. the functions only have a single handler and there is no global pre or pos middlewares.

I'm pushing a fix for this.
If you can think of anything else, please let me know

Hi @juanjoDiaz thanks for the quick reply
the versions I'm using:

  • serverless-middleware: 0.0.11
  • serverless-offline: ^5.12.0

reggarding the second issue, I think it's the opposite, first cause I can actually see that the .middleware folder was created, but it will not delete (cleanup) when I tried to finish the process (maybe there is something with R/W permissions but I'm on windows so it shouldn't be a matter)

reggarding no functions using middleware, I had one using it (as I said I was just testing so I put a middleware just to try and this happened), so currently the .middleware folder it's just hanging around non removed

Also, terrific work with this middleware, I used it for a previous project a while ago and solved a lot of issues ๐Ÿ‘

Glad that you are finding this plugin useful! ๐Ÿ™‚

Saw that you put a message saying that this was fixed but then removed it.
What is the status on this?
Could you share a repo that I can use to replicate the issue?

Yeah, the problem persist, I just created this repo to replicate the error
https://github.com/xaeli/middleware-test

Awesome thanks!

This should be fixed in version 0.0.12

Let me know if you find anything else ๐Ÿ™‚