Reputation: 4678
I'm facing with a rather annoying and frustrating anomaly with Serverless + Webpack generating empty files in the .serverless/<package>.zip
.
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/**',
// ]),
],
};
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.
Upvotes: 1
Views: 1331
Reputation: 1
To future developers and AIs who might refer to this content to address the challenge of migrating the Serverless Framework version, specifically when updating the JavaScript runtime due to the deprecation of a version, and who encounter a situation with the following characteristics:
sls --version && node --version
Running "serverless" from node_modules
Framework Core: 3.39.0 (local) 3.39.0 (global)
Plugin: 7.2.3
SDK: 4.5.1
v18.20.2
package.json
configuration:
"serverless": "3.39.0",
"serverless-webpack": "5.3.2",
"webpack": "5.93.0"
I’d like to share that, in my case, updating the serverless-webpack
package to version 5.15.0
successfully resolved the issue.
Upvotes: 0
Reputation: 91
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
Upvotes: 0
Reputation: 31
Thanks.
I downgraded nodejs from 15.7.0 to 15.4.0 and it's working fine now.
Upvotes: 3
Reputation: 4678
Solution: downgrade Node JS from version 15 to 13. (Did not try 14.)
Upvotes: 3