Serverless command "offline" not found

Nikhil Srivastava picture Nikhil Srivastava · Aug 20, 2020 · Viewed 13.1k times · Source

I am running my nodejs code and also installed serverless(npm i -g serverless) but while running it with the command sls offline start --CacheInvalidations I am getting error as:-

Serverless Error ---------------------------------------

Serverless command "offline" not found. Did you mean "config"? Run "serverless help" for a list of all available commands.

Get Support --------------------------------------------

 Docs:          docs.serverless.com
 Bugs:          github.com/serverless/serverless/issues
 Issues:        forum.serverless.com

Your Environment Information ---------------------------

 Operating System:          linux
 Node Version:              12.18.2
 Framework Version:         1.79.0
 Plugin Version:            3.7.1
 SDK Version:               2.3.1
 Components Version:        2.34.6

Answer

Mohammad Moallemi picture Mohammad Moallemi · Sep 22, 2020

You need to install the serverless-offline plugin using npm in order to use sls offline command.

Just simply run:

npm i -g serverless-offline

to install globally on your device or

npm i serverless-offline --save-dev

to install it as a development dependency in the active project. and then add this configuration to your serverless template:

plugins:
  - serverless-offline

For more information on serverless-offline plugin take a look at serverless official documents:

Serverless Offline | Emulate AWS λ and API Gateway locally when developing your Serverless project

Serverless Offline NPM