Serverless command "offline" not found
Asked Answered
A

9

19

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
Adalie answered 20/8, 2020 at 14:20 Comment(2)
In my case, I had the module correctly under node_modules and still it was not working. I found the issue that I was executing the command >sls offline start from the base application folder, but you have to execute the command from the SERVICE_FOLDER. Hope this might help somebody....Teferi
in my case i had to run sudo npm install serverless -g and worked like a charmRhodos
E
19

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

Effluvium answered 22/9, 2020 at 18:49 Comment(4)
make sure you hit save on your serverless template, I'm used to work with auto saving IDE, so when I switched to something else I forgot to save after adding the pluginAuthenticity
ok, one more important thing is that serverless.yaml has to be in the same folder where the node_modules folder isJuieta
@Madeo but serverless generally while creating a project it's going to create folder right, can we point out the plugin to refer one folder up is that possible ?Blacksmith
I had the same problem, the serverless.yml was in src instead in the root project. 30 minutes lost foreverWorthy
P
5

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

Pipsissewa answered 17/2, 2022 at 17:5 Comment(0)
P
2

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

Install:

yarn add serverless-offline -D

Run:

yarn serverless offline start
Pharmacognosy answered 17/10, 2020 at 18:59 Comment(0)
M
2

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 
Measure answered 20/5, 2023 at 5:5 Comment(0)
S
0

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

Spermophile answered 7/10, 2020 at 16:13 Comment(0)
E
0

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

Endopeptidase answered 13/10, 2020 at 2:45 Comment(0)
M
0

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
Mccarter answered 2/11, 2020 at 19:23 Comment(0)
D
0
  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
Dusk answered 1/9, 2021 at 7:57 Comment(0)
P
0

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

Peyton answered 31/5, 2022 at 12:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.