我正在尝试使用无服务器部署到 Lambda。在我的 webpack.config 中.js我有以下条目:
const slsw = require('serverless-webpack')
module.exports = {
entry: slsw.lib.entries,
...
}
在我的无服务器.yml中,我将函数声明如下:
functions:
importUsersFromS3:
handler: handlers.handler
和处理程序.js如下所示:
exports.handler = async function (event, context) {
awaitcaptureAsyncFunc('handleSplitSpreadsheet', () => {
context.callbackWaitsForEmptyEventLoop = false
log('event', { event })
processLargeSpreadsheet(event, context)
})
}
当我运行serverless webpack --out dist --stage dev --region us-east-1
时出现以下错误:
Webpack Options Validation Error -----------------------
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.entry should be an non-empty object.
-> Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.
at webpack (/src/node_modules/webpack/lib/webpack.js:31:9)
at ServerlessWebpack.compile (/src/lambda/usersApi/node_modules/serverless-webpack/lib/compile.js:12:22)
From previous event:
at PluginManager.invoke (/usr/lib/node_modules/serverless/lib/classes/PluginManager.js:464:22)
at PluginManager.spawn (/usr/lib/node_modules/serverless/lib/classes/PluginManager.js:484:17)
at ServerlessWebpack.BbPromise.bind.then.then (/src/lambda/usersApi/node_modules/serverless-webpack/index.js:150:51)
at runCallback (timers.js:810:20)
at tryOnImmediate (timers.js:768:5)
at processImmediate [as _immediateCallback] (timers.js:745:
所以我的文件夹结构是这样的
app
├── lambda
| ├── usersApi
| | ├── handlers.js
| | ├── serverless.yml
| | └── package.json
| ├── severalServiceFolders
| └── webpack.config.js
└── package.json
app/lambda/usersApi/package.json
年,我有这些开发依赖项:
"serverless-plugin-aws-alerts": "1.2.4",
"serverless-plugin-tracing": "^2.0.0",
"serverless-webpack": "^5.3.1"
事实证明,删除它们会使错误消失。
仅"serverless-webpack": "^5.3.1"
对根package.json
中serverless
的引用