简体   繁体   中英

Serverless plugin "serverless-offline" not found. Make sure it's installed and listed in the "plugins" section of your serverless config file

When I deploy my SLS project, I get the following error:

Serverless plugin "serverless-offline" not found. Make sure it's installed and listed in the "plugins" section of your serverless config file

But I did install the plugin serverless-offline correctly, please can someone help me fix it.

Here is my serverless.yml file:

   service: email-sender

    provider:
      name: aws
      runtime: nodejs4.3

    functions:
      send:
        handler: handler.send
        events:
          - http:
              path: submissions
              method: post
              response:
                headers:
                  Content-Type: "text/json"
              cors:
                origins:
                  - '*'
    package:
      exclude:
        - node_modules/**
      include:
        - node_modules/serverless-offline/**

    plugins:
      - serverless-offline

Serverless offline is a plugin to run only on your development machine, not in production.

To enable it add the following to serverless.yml :

    plugins:
      - serverless-offline

and remove the following lines

      include:
        - node_modules/serverless-offline/**

also check your package.json and make sure it is a devDependencies .

Please ensure that serverless-offline package is included in dev dependencies, if not then add it

"serverless-offline": "3.20.2"

and run,

npm install --save-dev

This solved my issue.

To resolve this error while running an automated CI pipeline or locally, try the following:

- npm config set prefix /usr/local
- npm install -g serverless
- npm install serverless-offline -g
- npm install --save-dev
- serverless deploy --stage production --verbose

Also, check your package.json and ensure the serverless-offline package is included in devDependencies .

This fixed the issue for me.

Happy Serverless!

I encountered a similar issue on bitbucket pipelines. I fixed the issue (after many trials and errors) by updating "script" section of your bitbucket-pipelines.yml file with the following:

          script:
            - npm install -g npm
            - npm install --save-dev
            - pipe: atlassian/serverless-deploy:1.1.1
              variables:
                AWS_ACCESS_KEY_ID: $KEY_DEFINED_ON_BITBUCKET
                AWS_SECRET_ACCESS_KEY: $KEY_DEFINED_ON_BITBUCKET

Also, check your package.json and ensure the serverless-offline package and any other plugins in the serverless.yml file are included in devDependencies .

Big thanks to K Manoj Kumar's answer for giving me a clue.

If you are not using bitbucket pipeline, I feel replacing the "pipe" section on the bitbucket-pipelines.yml file with something like npm run deploy and adding "deploy": "serverless deploy" to the "scripts" section on your package.json will work.

The error is resolved by installing the package

npm install serverless-offline -g

If the serverless package is not added, do add that:

npm i -g serverless

The terminal commands and the console logs shown below:

keerthipriyagkurtakoti@Keerthipriyas-MacBook-Pro aws-node-express-api % npm start                          

> aws-node-express-api@1.0.0 start /Users/keerthipriyagkurtakoti/Desktop/krishnaWorkspace/Educative/educative/aws-node-express-api
> nodemon --exec serverless offline

[nodemon] 2.0.19
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `serverless offline`
Environment: darwin, node 14.16.1, framework 3.21.0, plugin 6.2.2, SDK 4.3.2
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Serverless plugin "serverless-offline" not found. Make sure it's installed and listed in the "plugins" section of your serverless config file. Run "serverless plugin install -n serverless-offline" to install it.
[nodemon] app crashed - waiting for file changes before starting...
^C%                                                                                                                                            keerthipriyagkurtakoti@Keerthipriyas-MacBook-Pro aws-node-express-api % npm install serverless-offline -g
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN serverless-offline@8.8.1 requires a peer of serverless@^1.60.0 || 2 || 3 but none is installed. You must install peer dependencies yourself.

+ serverless-offline@8.8.1
added 192 packages from 267 contributors in 34.928s
keerthipriyagkurtakoti@Keerthipriyas-MacBook-Pro aws-node-express-api % npm start                        

> aws-node-express-api@1.0.0 start /Users/keerthipriyagkurtakoti/Desktop/krishnaWorkspace/Educative/educative/aws-node-express-api
> nodemon --exec serverless offline

[nodemon] 2.0.19
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `serverless offline`

Starting Offline at stage dev (us-east-1)

Offline [http for lambda] listening on http://localhost:3002
Function names exposed for local invocation by aws-sdk:
           * user: aws-node-express-api-dev-user
           * test: aws-node-express-api-dev-test
           * authentication: aws-node-express-api-dev-authentication
           * postFeed: aws-node-express-api-dev-postFeed

   ┌──────────────────────────────────────────────────────────────────────────────────┐
   │                                                                                  │
   │   ANY | http://localhost:4000/dev/user/{any*}                                    │
   │   POST | http://localhost:4000/2015-03-31/functions/user/invocations             │
   │   ANY | http://localhost:4000/dev/test/{any*}                                    │
   │   POST | http://localhost:4000/2015-03-31/functions/test/invocations             │
   │   ANY | http://localhost:4000/dev/auth/{any*}                                    │
   │   POST | http://localhost:4000/2015-03-31/functions/authentication/invocations   │
   │   ANY | http://localhost:4000/dev/social/{any*}                                  │
   │   POST | http://localhost:4000/2015-03-31/functions/postFeed/invocations         │
   │                                                                                  │
   └──────────────────────────────────────────────────────────────────────────────────┘

Server ready: http://localhost:4000 🚀

Enter "rp" to replay the last request

Error is shown in the picture below在此处输入图像描述

The error being addressed in the picture below:

在此处输入图像描述

I kept getting this error as I had the NODE_ENV set to "production" in my local dev environment.

serverless-offline does not work with this I believe. So set NODE_ENV to "development" or something that's not "production"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM