serverless icon indicating copy to clipboard operation
serverless copied to clipboard

Uploaded file must be a non-empty zip again with Node16

Open Bastczuak opened this issue 3 years ago • 29 comments

Are you certain it's a bug?

  • [X] Yes, it looks like a bug

Is the issue caused by a plugin?

  • [X] It is not a plugin issue

Are you using the latest version?

  • [X] Yes, I'm using the latest version

Is there an existing issue for this?

  • [X] I have searched existing issues, it hasn't been reported yet

Issue description

Hello,

seems like the problem Uploaded file must be a non-empty zip which was resolved in #8772 is now appearing again when using Node 16.15.1 (at point int time the latest lts version). Seems like the problem is again in node-archiver / crc32-stream. A workaround is available by using node <= 15.5.

Service configuration (serverless.yml) content

N/A

Command name and used flags

N/A

Command output

Uploaded file must be a non-empty zip
unzip .serverless/cloud-sensors.zip
Archive:  cloud-sensors.zip
  inflating: src/checks/check-executor.js   bad CRC 64419a3d  (should be 00000000)

Environment information

Framework Core: 3.18.2 (local)
Plugin: 6.2.2
SDK: 4.3.2

Bastczuak avatar May 30 '22 14:05 Bastczuak

Same here, using Serverless 3.19 and Node 16.15.1

Nicoowr avatar Jun 13 '22 15:06 Nicoowr

Same here:

serverless -v
Framework Core: 3.19.0
Plugin: 6.2.2
SDK: 4.3.2
node -v
v16.15.1

davidalejandroaguilar avatar Jun 14 '22 00:06 davidalejandroaguilar

facing same issue

rohityadav225 avatar Jun 29 '22 14:06 rohityadav225

Hey @rohityadav225 - are you on the latest version of the Framework? What installation method do yo use? Which Node version are you using?

pgrzesik avatar Jun 29 '22 14:06 pgrzesik

Hi @pgrzesik Below are the details

npm install -g serverless

Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              16.15.1
     Framework Version:         1.80.0
     Plugin Version:            3.8.1
     SDK Version:               2.3.1
     Components Version:        2.34.9

rohityadav225 avatar Jun 29 '22 14:06 rohityadav225

Based on the output you're on a very old Framework version @rohityadav225

pgrzesik avatar Jun 29 '22 16:06 pgrzesik

updating to latest framework version fixed the problem but i see the following warning(s)

npm install --location=global [email protected]
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated [email protected]: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731)

rohityadav225 avatar Jun 29 '22 17:06 rohityadav225

I have the same issue when using serverless-webpack and the following

Environment: darwin, node 16.14.0, framework 3.21.0, plugin 6.2.2, SDK 4.3.2

tobilg avatar Jul 14 '22 21:07 tobilg

@tobilg seems like the authors of the code bases fixed something. I can confirm that this problem is solved forr me (macos) by using the latest version of serverless and latest lts of node. Try to use node 16.16.0 with serverless 3.21.0.

Bastczuak avatar Jul 15 '22 07:07 Bastczuak

Just so this is in here for those having an issue still I wanted to share how I fixed the issue on my end.

I had to switch back to an earlier version of NodeJS (v14 LTS). I highly recommend using NVM (Node Version Manager) so you can switch back to the newer version.

I also used the latest version of Serverless (v3 at the time) since it claims to have backwards compatibility.

That was it honestly. Not a full intuitive answer as to why, probably something deprecated I'd guess.

nyle-mrevel avatar Jul 26 '22 14:07 nyle-mrevel

This error is still occurring with the latest versions of Node & Serverless :(

✖ Stack ******* failed to deploy (91s)
Environment: darwin, node 16.16.0, framework 3.21.0 (local), plugin 6.2.2, SDK 4.3.2
Credentials: Local, "default" profile
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
UPDATE_FAILED: ListLambdasVersionsLambdaFunction (AWS::Lambda::Function)
Resource handler returned message: "Uploaded file must be a non-empty zip (Service: Lambda, Status Code: 400, Request ID: ...)" 

Nicoowr avatar Aug 05 '22 10:08 Nicoowr

@Bastczuak this still persists, even with the latest versions:

$ sls -v && node -v 
Framework Core: 3.21.0
Plugin: 6.2.2
SDK: 4.3.2

v16.16.0

Error:

UPDATE_FAILED: ListLambdaFunction (AWS::Lambda::Function)
Resource handler returned message: "Uploaded file must be a non-empty zip (Service: Lambda, Status Code: 400, Request ID: 035629c1-4218-4041-9c8b-a2cf3e511f99)"

cc @mnapoli

tobilg avatar Aug 08 '22 11:08 tobilg

big oof. Im a 100% sure it worked before closing the ticket. Then I'll reopen it.

Bastczuak avatar Aug 08 '22 12:08 Bastczuak

@Bastczuak Something very weird happened on my side:

  • First it worked when I upgraded to the new versions (16.16.0/3.21).
  • Then I downgraded to 16.14.0 to be sure it really was this upgrade that made the deploy work. The deploy failed.
  • Finally I upgraded again to 16.16.0, but the deploy didn't work anymore

Nicoowr avatar Aug 08 '22 14:08 Nicoowr

Hey everyone, I'm trying to reproduce it but can't (all works fine). Though I have Node 18.3.0, has anyone tried upgrading to a higher major Node version? Given the last comment, it seems it's not consistent with the Node version, so that might be something else.

If you use any plugins please list them as well, that could help!

mnapoli avatar Aug 15 '22 14:08 mnapoli

@mnapoli I can reproduce this with node 16.15 - no plugins, last serverless version

crash7 avatar Aug 23 '22 16:08 crash7

tl;dr: Upgrade serverless-webpack

Background I'm seeing this still with node 16.16 and serverless 3.21.0. When I unzip the packaged zips, I'm still seeing bad CRCs:

$ 7z l -slt notify.zip | grep -e Path -e CRC
Path = notify.zip
Path = src/circle-mask.png
CRC = 00000000
Path = src/notify-user-handler.js
CRC = 00000000
Path = src/notify-user-handler.js.map
CRC = 00000000

This is confirmed when unzipping:

$ unzip notify.zip 
Archive:  notify.zip
  inflating: src/circle-mask.png      bad CRC ccece94a  (should be 00000000)
  inflating: src/notify-user-handler.js   bad CRC cce37a62  (should be 00000000)
  inflating: src/notify-user-handler.js.map   bad CRC 28afd87b  (should be 00000000)

@Bastczuak mentioned this may have something to do with node-archiver but says it was fixed for them in 3.21.0 (the same version I'm using): https://github.com/archiverjs/node-archiver/issues/594

My serverless-webpack version is 5.3.1 which is including [email protected]

Solution When I upgraded serverless-webpack to 5.9.0, it requires [email protected]. I think this updated archiver version solved the bad CRCs which also solved the "empty file" problem on deploy.

I think the new archiver includes a new version of crc32-stream which was affected by this zlib behavior change in Node v15.6.0.

timtrinidad avatar Aug 25 '22 16:08 timtrinidad

Thanks for your solution @timtrinidad ! However it does not solve the problem for those not using serverless-webpack I guess

Nicoowr avatar Aug 25 '22 16:08 Nicoowr

Ah. In that case, I would do a yarn why crc32-stream or npm ls crc32-stream to see which package needs to be updated. AFAIK you need crc32-stream@>=4.0.2 for node@>15.6.0

timtrinidad avatar Aug 25 '22 16:08 timtrinidad

Thanks @timtrinidad Actually it seems [email protected] requires crc32-stream@>=4.0.1 so we ended up using resolutions field in our monorepo to enforce ^4.0.2 version:

  "resolutions": {
    "crc32-stream": "^4.0.2"
  }

Now everything works.

Nicoowr avatar Sep 02 '22 08:09 Nicoowr

I also had the same issue, using Node 16.17.0, I know my framework version is old.

Just upgrading this package did the job. "serverless-webpack": "^5.9.1",

This is my environment configuration.

Your Environment Information --------------------------- Operating System: linux Node Version: 16.17.0 Framework Version: 2.2.0 (local) Plugin Version: 4.0.4 SDK Version: 2.3.2 Components Version: 3.1.4

orlin7 avatar Sep 08 '22 20:09 orlin7

I'm using serverless with next.js and named the sls project the same name as the directory:

#!/bin/bash

# current folder name
PRJ=`pwd | rev | cut -d '/' -f 1 | rev`
# zip file name
ZIP=$PRJ.zip

echo ==============================================
echo Serverless fails to package zip file correctly
echo Patching $ZIP
echo ==============================================

cd $PRJ
sls package
cd .serverless
unzip $ZIP -d output
rm $ZIP
cd output
zip -r ../$ZIP *
cd ..
rm -rf output
SHA=`shasum -a 256 $ZIP | cut -d ' ' -f1 | xxd -r -p |base64`
sed -i.old "s#\"CodeSha256\": \"[^\"]*\"#\"CodeSha256\":\"${SHA}\"#g" *.json
rm *.old
cd ..
sls deploy --package .serverless

arcanereinz avatar Nov 02 '22 08:11 arcanereinz

my error was fixed when running npm install serverless

and editing the package.json files

    "serverless-bundle": "^4.3.1",
    "serverless-dotenv-plugin": "^2.1.1",
    "serverless-offline": "^5.3.3"

and

    "serverless": "^3.26.0",

It now deploys without the error.

Aadil151 avatar Dec 23 '22 22:12 Aadil151

Facing same issue with Node 18.13.0 and serverless 3.34.0.

sushil-akkawar avatar Sep 12 '23 09:09 sushil-akkawar

@sushil-akkawar

Facing same issue with Node 18.13.0 and serverless 3.34.0.

I used "npm update" to update all dependencies and it worked for me

clptrinh avatar Sep 14 '23 00:09 clptrinh

if you use serverless-webpack, It would be good to try updating to the latest version (5.13.0). The conbination between serverless-webpack 5.3.0 and node 18.15.0 did not work in my environment.

several while in debugging, I found that the reason was that appending buffered data to the zip file was failure.

There are a lot of updates on that part in the 5.13.0. In my local environment, totally worked well.

Running "serverless" from node_modules Framework Core: 3.35.2 (local) 3.30.1 (global) Plugin: 7.0.5 SDK: 4.4.0

haruharuharuby avatar Oct 19 '23 15:10 haruharuharuby

Hi i'm having issue

node 18.12
"serverless-webpack": "5.3.0",
"serverless": "3.36.0",
"serverless-offline-ssm": "^6.2.0",
"serverless-offline": "13.2.1",

Environment: linux, node 18.12.1, framework 3.36.0 (local), plugin 7.1.0, SDK 4.4.0
Credentials: Local, environment variables
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

image

juztinlazaro avatar Nov 09 '23 16:11 juztinlazaro

Same issue here using node v 20

mvergaray avatar Feb 13 '24 05:02 mvergaray