Serverless-offline: `runProxyHandler` requires global install of Serverless

Created on 2 May 2019  路  5Comments  路  Source: dherault/serverless-offline

We have been attempting to use this plugin to run automated integration tests to make sure our dozens of endpoints are hooked up properly, but the biggest hitch is that we don't have serverless installed globally, as that would break the ability to version Serverless on a per-project level.

When running via node_modules/.bin/serverless offline ... or yarn sls offline ... we see the long list of Lambda endpoints and everything looks fine, but trying to actually call one breaks with the following error...

Serverless: GET /endpoint (位: some-endpoint
Serverless: Failure: /bin/sh: sls: command not found

... which, I believe, is a result of this attempt to spawn a new sls process via a globally-installed Serverless package.

Most helpful comment

Fixed in v4.10.0

All 5 comments

Hi @kevlarr
You can have a look of how serverless-offline is used to test its own lib (under /test).
Or
Can you provide me a stacktrace ?

@dherault Ah apologies, my submitted issue might not have been that clear. There isn't a stacktrace, just a list of the endpoints that serverless-offline finds and then that Serverless: Failure: /bin/sh: sls: command not found message immediately below when I try to call it.

I'm testing in the same way as this package's integration tests, namely via local HTTP calls to the host/port (which is how that above failure happens).

The issue is that we do not (and cannot) have access to the sls command, since we are not able to rely on that package being globally-installed. We use it either via yarn sls or node_modules/.bin/sls rather than just sls - availability of that latter command is what this plugin expects right here, which is the root of the failure for us, I think.

For instance, if I change that line to spawn('yarn sls', ...) then it actually works for us, because it's using the package-version of Serverless. Obviously, I wouldn't embed yarn in the string like that, but I'm not sure what a good solution would be for allowing local installs.

That works because we have a "sls": "node_modules/.bin/sls" script in our package.json

Perhaps there could be a flag that lets one specify where the path to the npm package is if not installed globally, eg. something like:

$ yarn sls offline --slsPath node_modules/.bin/sls

Fixed in v4.10.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MEGApixel23 picture MEGApixel23  路  4Comments

aldofunes picture aldofunes  路  3Comments

dnalborczyk picture dnalborczyk  路  3Comments

ozbillwang picture ozbillwang  路  4Comments

ghost picture ghost  路  4Comments