如何在macOS中配置和使用无服务器脱机?

时间:2019-07-15 06:37:37

标签: npm package.json serverless-framework serverless-offline

我正在尝试通过无服务器框架使用无服务器离线库,
我使用-

正确配置了serverless.yaml文件
plugins:
  - serverless-offline

已添加到其中。

以下是我的package.json-

{
  "name": "serverless-test",
  "version": "1.0.0",
  "description": "Lambda APIs for Test Module",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "./node_modules/.bin/serverless offline -s dev",
    "debug": "export SLS_DEBUG=* && node --debug ./node_modules/.bin/serverless offline -s dev"
  },
  "author": "Aniruddha",
  "license": "ISC",
  "dependencies": {
    "async": "^2.6.2",
    "aws-sdk": "^2.447.0",
    "axios": "^0.18.0",
    "jsonwebtoken": "^8.5.1",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.25",
    "mysql": "^2.17.1"
  },
  "devDependencies": {
    "serverless-offline": "4.9.4"
  }
}

我使用以下命令安装软件包-

npm i

也跑了-

npm i dev

然后运行sls offlineserverless offline
运行脱机模式。

但是我遇到了以下错误-

bash: sls: command not found

bash: serveless: command not found

我检查了npm日志并找到了-

112 error code EBADPLATFORM
113 error notsup Unsupported platform for inotify@1.4.6: wanted {"os":"linux","arch":"any"} (current: {"os":"darwin","arch":"x64"})
114 error notsup Valid OS:    linux
114 error notsup Valid Arch:  any
114 error notsup Actual OS:   darwin
114 error notsup Actual Arch: x64
115 verbose exit [ 1, true ]

我可以在ubuntu上使用无服务器脱机罚款,
但在Mac上无法做到,
有解决办法吗?

1 个答案:

答案 0 :(得分:0)

您的问题不是serverless offline插件,而是Serverless Framework插件:未安装,因此您得到

  找不到

sls(或无服务器)命令

只需运行npm install serverless -g。请记住,取决于您如何设置npm,您可能需要sudo权限才能全局安装软件包。