'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
Solution 1:[1]
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
Solution 2:[2]
I was facing the same issue while setting up serverless.yml with nodejs and running it on local. Two steps resolved the problem.
- Install serverless-offline package globally.
npm i -g serverless-offline
- Add the same package under the plugin key of your serverless.yml file.
plugins: - serverless-offline
Solution 3:[3]
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
Solution 4:[4]
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
Solution 5:[5]
Installing the dependency with yarn you can run the command typing the following:
Install:
yarn add serverless-offline -D
Run:
yarn serverless offline start
Solution 6:[6]
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
Solution 7:[7]
- make sure serverless-offline is installed (globaly or at the project)
- Add these lines to serverless.yml
plugins:
# Needed to run & debug locally
- serverless-offline
Solution 8:[8]
Try in your project with the npx prefix. So npx sls offline or npx serverless offline. It worked for me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
