webpack: configuration.entry должен быть непустым объектом
serverless deploy
выдает эту ошибку с последней версией веб-пакета.
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' },
],
},
};
package.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 здесь, любая помощь очень ценится.
1 ответ
Решением было воссоздать проект с нуля и переустановить пакеты:sls create --template aws-nodejs-typescript --path projectname
в этом случае сгенерированный файл webpack.config.json выглядит так:
const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = {
context: __dirname,
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
entry: slsw.lib.entries,
devtool: slsw.lib.webpack.isLocal ? 'cheap-module-eval-source-map' : 'source-map',
resolve: {
extensions: ['.mjs', '.json', '.ts'],
symlinks: false,
cacheWithContext: false,
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
target: 'node',
externals: [nodeExternals()],
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{
test: /\.(tsx?)$/,
loader: 'ts-loader',
exclude: [
[
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, '.serverless'),
path.resolve(__dirname, '.webpack'),
],
],
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
},
],
},
plugins: [
// new ForkTsCheckerWebpackPlugin({
// eslint: true,
// eslintOptions: {
// cache: true
// }
// })
],
};
и package.json:
"@types/aws-lambda": "^8.10.17",
"@types/node": "^10.12.18",
"fork-ts-checker-webpack-plugin": "^3.0.1",
"serverless": "^1.73.1",
"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.2.0",
"ts-loader": "^5.3.3",
"typescript": "^3.2.4",
"webpack": "^4.29.0",
"webpack-node-externals": "^1.7.2"
развертывание как офлайн, так и в облаке работает нормально.