yarnpkg - 无服务器离线:“路径”参数必须是字符串类型。收到未定义
问题描述
不知道为什么会发生这种情况,但我有一个非常简单的无服务器应用程序正在运行,但现在当我运行时,sls offline start
我得到了上面的错误。我找到了罪魁祸首,它是events
函数内部。
这是serverless.yml
文件:
service: hello-world-offline
provider:
name: aws
runtime: nodejs12.x
region: eu-east-1
stage: dev
plugins:
- serverless-offline
functions:
hello-world:
handler: handler.handle # required, handler set in AWS Lambda
events:
- http:
path: hello-world
method: get
cors: true
这是handler.js
文件:
module.exports.handle = async (event, ctx, cb) => {
cb(null, {
statusCode: 200,
body: JSON.stringify({ message: "hello world" })
})
}
如果我去掉events
函数中的hello-world
一切都可以正常工作,sls offline start
除了我当然不能在本地实际命中端点。我尝试通过添加引号使其成为硬字符串,但没有任何作用。
编辑:原来这发生在使用yarn workspaces
. 如果我把它放在一个packages/my-serverless-app
结构中并 cd 到文件夹中运行sls offline start
命令,就会发生这种情况。如果我将它从结构中移除,它就可以正常工作。
解决方案
改变
events:
- http:
path: hello-world
method: get
cors: true
至
events:
- httpApi:
path: hello-world
method: get
这应该工作!
推荐阅读
- python - ModuleNotFoundError:没有名为“cassandra.cluster”的模块;'cassandra' 不是一个包
- mysql - 在 MySQL 中,是否可以更新 information_schema.COLUMNS 表以设置 COLUMN_DEFAULT 和/或 IS_NULLABLE 而不是使用 ALTER TABLE?
- r - 如何根据这些行中的值有条件地删除矩阵的行?
- python - 这两种方法有什么区别?
- typescript - 修复代码时,nodemon 不重启服务器
- postgresql - 使用 pg_dump 和 psql 迁移时 Azure Server for PostgreSQL 失败
- node.js - 角 CLI 12.2 | 创建新项目后找不到许多模块
- pytorch - DistributedDataParallel 是否需要 Dataloader 中的屏障
- javascript - Firebase 存储不会下载并添加到 firebase 数据库
- google-play-console - 发生意外的错误。请再试一次。(7A99E156)