Serverless command "offline" not found. VS Code Debugger

Viewed 1508

I have the following launch.json file.

  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Serverless Offline",
      "program": "${workspaceRoot}/node_modules/serverless/bin/serverless",
      "args": ["offline", "start", "--httpPort", "4000", "--noTimeout"],
      "protocol": "inspector",
      "runtimeExecutable": "node",
      "resolveSourceMapLocations": [
        "${workspaceFolder}/**",
        "!**/node_modules/**"
      ]
    }

But I get the following error when I run the debugger from vs code. I do have both serverless and serverless-offline installed as a dev dependency. Does the project structure has an impact on it. my node_modules folder is not the root folder.

And also included in the serverless.yml file.

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

3 Answers

Your serverless.yml file needs to be in the same folder where node_modules folder is located. Also, ensure you ran npm install and the serverless.yml contains the following

plugins:
  - serverless-offline

Follow the readme in https://www.npmjs.com/package/serverless-offline

Answering based on below statements,

my node_modules folder is not the root folder. serverless.yml it is in the same folder as node_modules

Make sure you're running serverless offline or sls offline from the directory where the serverless.yml is located.

If you need to run it from outside of the directory where the serverless.yml is located, you can change the script which uses serverless-offline to first change the current working directory.

Ex: cd <path to the directory of serverless.yml> && serverless offline

Side note: Also make sure the indentation of the serverless.yml is correct

Can you try running which serverless from your command line?

Did you try running with the global serverless executable (not the one from node_modules)?

Related