如何解决无服务器 Webpack 生成 ZIP 包中的空文件 配置其他数据
Serverless + 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 中的文件是空的?? ?
更新:
我刚刚尝试在 example projects 之一中运行 sls package
,结果相同,ZIP 中的文件为空。
解决方法
谢谢。
我将 nodejs 从 15.7.0 降级到 15.4.0,现在工作正常。
,解决方案:将Node JS从15版降级到13版。(14版没试过)
,使用 nvm 管理不同版本的节点。
我的节点版本 v15.8.0 出现了这个问题。通过使用nvm将系统版本降级到v14.15.5解决。
参考 - https://forum.serverless.com/t/empty-files-in-uploaded-zip/13777
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。