无服务器 slsw.lib.entries 始终为空

serverless slsw.lib.entries is always empty

我正在尝试使用无服务器部署到 Lambda。在我的 webpack.config.js 中,我有以下条目:

const slsw = require('serverless-webpack')
module.exports = {
  entry: slsw.lib.entries,
  ...
}

在我的 serverless.yml 中,我声明函数如下:

functions:
  importUsersFromS3:
    handler: handlers.handler

和 handlers.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 我有这些 devDependencies:

"serverless-plugin-aws-alerts": "1.2.4",
"serverless-plugin-tracing": "^2.0.0",
"serverless-webpack": "^5.3.1"

原来删除它们使错误消失了。

仅在根 package.json 中引用 serverless"serverless-webpack": "^5.3.1"