Serverless Webpack generates empty files in ZIP package

1.2k views Asked by At

I'm facing with a rather annoying and frustrating anomaly with Serverless + Webpack generating empty files in the .serverless/<package>.zip.

enter image description here

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.

3

There are 3 answers

0
haxpanel On BEST ANSWER

Solution: downgrade Node JS from version 15 to 13. (Did not try 14.)

1
PPRB On

Thanks.

I downgraded nodejs from 15.7.0 to 15.4.0 and it's working fine now.

0
riyas On

Use nvm to manage different versions of the node.

The issue was happening for me with node version v15.8.0. Resolved by downgrading system version to v14.15.5 using nvm.

Reference - https://forum.serverless.com/t/empty-files-in-uploaded-zip/13777