问题描述
我正在尝试第一次使用无服务器,尽管我认为我已经遵循了文档等,但是却遇到了奇怪的错误。
我已经安装了无服务器和一些功能:
npm install -g serverless
npm install -g serverless-plugin-optimize
sls invoke local -f auth-handler -s local
Serverless: To ensure safe major version upgrades ensure "frameworkVersion" setting in service configuration (recommended setup: "frameworkVersion: ^2.1.1")
Serverless Error ---------------------------------------
ServerlessError: Serverless plugin "sls" not found. Make sure it's installed and listed in the "plugins" section of your serverless config file.
at C:\Users\cw\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:155:17
...
如您所见,我正在调用sls及其运行(我已导出SLS_DEBUG=* sls
进行调试)
sls将其报告为环境:
Your Environment @R_228_4045@ion
---------------------------
Operating System: win32
Node Version: 12.18.4
Framework Version: 2.1.1
Plugin Version: 4.0.4
SDK Version: 2.3.2
Components Version: 3.1.3
我的serverless.yml是:
service: serverless-optimize-example
provider:
name: aws
runtime: nodejs12.18
package:
individually: true
custom:
enable_optimize:
local: false
plugins:
- sls
- serverless-plugin-optimize
- serverless-offline
functions:
auth-handler:
handler: src/index.handler
optimize: ${self:custom.enable_optimize.${opt:stage,'dev'},'true'}
events:
- http:
path: /func1
method: get
即使看起来像已安装sls,我该怎么办?
更新 我工作了,谢谢@David Webster。就是这样:
Fixing npm path in Windows 8 and 10
%APPDATA%\npm
<path to nodejs>\node_modules\npm\bin e.g. C:\Program Files\nodejs\node_modules\npm\bin
解决方法
因此,除了我在更新中添加的路径问题之外,还有一个 MASSIVE 陷阱。我原本没有倒锅。我读过的其中一份文件说要补充:
plugins:
- sls
...
结果证明这是问题的根源。我的插件现在看起来像:
plugins:
- serverless-plugin-optimize
- serverless-offline