Serverless Webpack 在 ZIP 包中生成空文件
Serverless Webpack generates empty files in ZIP package
无服务器 + Webpack 在 .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/**',
// ]),
],
};
附加数据
- Serverless-Webpack 版本: "serverless-webpack": "^5.3.5",
- Webpack 版本: "webpack": "4.44.2",
- 无服务器框架版本: 1.83.2
- 操作系统: MacOS
我也尝试过其他版本组合:Serverless 2.20、webpack 5.17.0、copy-webpack-plugin 7.0.0
为什么 ZIP 中的文件为空??
更新:
我刚刚尝试 运行 sls package
中的一个 example projects 结果相同,ZIP 中的空文件。
解决方案:将 Node JS 从版本 15 降级到 13。(没有尝试 14。)
谢谢。
我将 nodejs 从 15.7.0 降级到 15.4.0,现在工作正常。
使用nvm管理不同版本的节点。
我的节点版本 v15.8.0 出现了这个问题。使用nvm将系统版本降级到v14.15.5解决。
参考 - https://forum.serverless.com/t/empty-files-in-uploaded-zip/13777
无服务器 + Webpack 在 .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/**',
// ]),
],
};
附加数据
- Serverless-Webpack 版本: "serverless-webpack": "^5.3.5",
- Webpack 版本: "webpack": "4.44.2",
- 无服务器框架版本: 1.83.2
- 操作系统: MacOS
我也尝试过其他版本组合:Serverless 2.20、webpack 5.17.0、copy-webpack-plugin 7.0.0
为什么 ZIP 中的文件为空??
更新:
我刚刚尝试 运行 sls package
中的一个 example projects 结果相同,ZIP 中的空文件。
解决方案:将 Node JS 从版本 15 降级到 13。(没有尝试 14。)
谢谢。
我将 nodejs 从 15.7.0 降级到 15.4.0,现在工作正常。
使用nvm管理不同版本的节点。
我的节点版本 v15.8.0 出现了这个问题。使用nvm将系统版本降级到v14.15.5解决。
参考 - https://forum.serverless.com/t/empty-files-in-uploaded-zip/13777