Nikhil Srivastava
Nikhil Srivastava

Reputation: 221

Serverless command "offline" not found

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

Upvotes: 20

Views: 39744

Answers (9)

KhangCao
KhangCao

Reputation: 21

There is another way to try with

 npx serverless plugin install --name serverless-offline

this is for install serverless-offline plugin. you also can view available plugin names bu

npx sls plugin list 

Upvotes: 2

Rutvi Trivedi
Rutvi Trivedi

Reputation: 93

Try in your project with the npx prefix. So npx sls offline or npx serverless offline. It worked for me.

Upvotes: 0

Rajat Upadhyay
Rajat Upadhyay

Reputation: 168

I was facing the same issue while setting up serverless.yml with nodejs and running it on local. Two steps resolved the problem.

  1. Install serverless-offline package globally.

npm i -g serverless-offline

  1. Add the same package under the plugin key of your serverless.yml file.

plugins:
- serverless-offline

Upvotes: 5

Elad Rubi
Elad Rubi

Reputation: 643

  1. make sure serverless-offline is installed (globaly or at the project)
  2. Add these lines to serverless.yml

plugins:
  # Needed to run & debug locally
  - serverless-offline

Upvotes: 0

tugberkgunver
tugberkgunver

Reputation: 33

First, you have to install serverless offline globally.

npm i -g serverless-offline

Next, you should check a serverless.yml file. Otherwise, you must create a serverless.yml file.

service: your-service-name
app: app-name
provider:
  name: aws
  runtime: nodejs10.x
  timeout: 60
  memorySize: 128
  deploymentBucket: bucket-name
# you can overwrite defaults here
  stage: prod
  region: your-aws-region
functions:
  your-function-name:
    handler: handler.dispatch
    memorySize: 128
    timeout: 60
    events:
      #- http: POST /hello
      - http: 'ANY {proxy+}'
plugins:
  - serverless-offline
  - serverless-aws-alias

Upvotes: 0

rigobcastro
rigobcastro

Reputation: 1257

Installing the dependency with yarn you can run the command typing the following:

Install:

yarn add serverless-offline -D

Run:

yarn serverless offline start

Upvotes: 2

Roberto Guajardo
Roberto Guajardo

Reputation: 490

Not sure if you solved this issue but I was having the same problem, for me it was a silly error, the indentation of the YML file was wrong, after fixing the indentation it started to work just fine

Upvotes: 0

Daniel Abib
Daniel Abib

Reputation: 1

You have to install the package (or locally in your project or globally). I do recommend install globally.

npm i -g serverless-offline

or

yarn global add serverless-offline

Inside your serverless.yml file, add in the plugins session the following code:

plugins:

  • serverless-offline

It will sove your problem

Upvotes: 0

Mohammad Moallemi
Mohammad Moallemi

Reputation: 658

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

Upvotes: 19

Related Questions