serverless deploy
使用最新的 webpack 版本抛出此错误。
Serverless: Bundling with Webpack...
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 a non-empty object.
webpack.config.js
const path = require('path');
const slsw = require('serverless-webpack');
// var nodeExternals = require('webpack-node-externals')
module.exports = {
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
entry: slsw.lib.entries,
// externals: [nodeExternals()],
devtool: 'source-map',
resolve: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
target: 'node',
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.tsx?$/, loader: 'ts-loader' },
],
},
};
包.json
"serverless": "^1.72.0",
"serverless-aws-documentation": "^1.1.0",
"serverless-dynamodb-local": "^0.2.39",
"serverless-iam-roles-per-function": "^2.0.2",
"serverless-offline": "^6.4.0",
"serverless-reqvalidator-plugin": "^1.0.3",
"serverless-s3-local": "^0.6.2",
"serverless-webpack": "^5.3.2",
"ts-loader": "^7.0.5",
"typescript": "^3.9.5",
"webpack": "^4.43.0"
这里有一些相关的东西:https ://github.com/serverless-heaven/serverless-webpack/issues/372
serverless.yml 是非常标准的,并且可以使用较旧的 webpack 版本。不是这里的 webpack 专家,非常感谢任何帮助。