I'm facing with a rather annoying and frustrating anomaly with Serverless + Webpack generating empty files in the .serverless/<package>.zip
.
Config
serverless.yml
...
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
...
webpack.config.js
const slsw = require("serverless-webpack")
const nodeExternals = require("webpack-node-externals")
// const CopyPlugin = require("copy-webpack-plugin")
module.exports = {
entry: slsw.lib.entries,
target: 'node',
// Generate sourcemaps for proper error messages
devtool: 'source-map',
// Since 'aws-sdk' is not compatible with webpack,
// we exclude all node dependencies
externals: [nodeExternals()],
mode: slsw.lib.webpack.isLocal ? "development" : "production",
optimization: {
// We do not want to minimize our code.
minimize: false
},
performance: {
// Turn off size warnings for entry points
hints: false
},
// node: false,
// devtool: 'inline-cheap-module-source-map',
// Run babel on all .js files and skip those in node_modules
module: {
rules: [
{
test: /\.js$/,
include: __dirname,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: { node: '12' },
useBuiltIns: 'usage',
corejs: 3,
},
],
],
},
},
],
},
],
},
plugins: [
// TODO
// new CopyPlugin([
// 'path/to/specific/file',
// 'recursive/directory/**',
// ]),
],
};
Additional Data
- Serverless-Webpack Version: "serverless-webpack": "^5.3.5",
- Webpack version: "webpack": "4.44.2",
- Serverless Framework Version: 1.83.2
- Operating System: MacOS
I have tried other version combinations too: Serverless 2.20, webpack 5.17.0, copy-webpack-plugin 7.0.0
Why empty files in ZIP??
Update:
I have just tried to run sls package
in one of the example projects with same result, empty files in ZIP.
Solution: downgrade Node JS from version 15 to 13. (Did not try 14.)