Serverless-webpack: Error on serverless deploy: zip error: Invalid command arguments (no such option: -)

Created on 8 Jul 2021  ·  5Comments  ·  Source: serverless-heaven/serverless-webpack

I have a serverless project, which I can deploy on one machine. When I try to deploy it on another machine, I get the following error. Both are Windows 10 .

zip error: Invalid command arguments (no such option: -)

 Error ---------------------------------------------------

  Error: Unexpected exit code from native zip: 16
   executed command 'zip --quiet --recurse-paths ..\post-asset.zip ./'
   executed in directory 'C:\Users\Administrator\Documents\ST\ST-Test-API\.webpack\post-asset'
      at ChildProcess.<anonymous> (C:\Users\Administrator\Documents\ST\ST-Test-API\node_modules\bestzip\lib\bestzip.js:86:13)
      at ChildProcess.emit (events.js:314:20)
      at ChildProcess.EventEmitter.emit (domain.js:483:12)
      at maybeClose (internal/child_process.js:1021:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)

The machine that has this error can deploy OTHER serverless project without a problem.
The error occurs in the webpack phase.
I have not found a similar problems online.

The complete YML and output are given below:


serverless.yml

# NOTE: update this with your service name
service: test-api

# Create an optimized package for our functions
package:
  individually: true

plugins:
  - serverless-bundle # Package our functions with Webpack
  - serverless-offline
  - serverless-dotenv-plugin # Load .env as environment variables

provider:
  name: aws
  runtime: nodejs14.x
  stage: dev
  region: eu-central-1
  tracing:
    lambda: true
  apiGateway:
    request:
      schemas:
        post-create-model:
          name: PostAddAsset
          schema: ${file(schemas/post-add-asset.json)}
        patch-update-model:
          name: PatchAddAsset
          schema: ${file(schemas/patch-update-asset.json)}
        delete-model:
          name: DeleteAsset
          schema: ${file(schemas/delete-asset.json)}
        patch-badge:
          name: PatchBadge
          schema: ${file(schemas/patch-badge.json)}

functions:
  post-asset:
    handler: post-asset.main
    events:
      - http:
          path: asset
          cors: true
          method: post
          integration: lambda
          private: true
          request:
            schemas:
              application/json: post-create-model
          response: &response-repeat
            headers:
              Content-Type: "'application/json'"
            template: $input.path('$')
            statusCodes:
              200:
                pattern: "" # Default response method
                template: $input.path("$.body")
              409:
                pattern: '.*"statusCode":409,.*' # JSON response
                template: $util.parseJson($input.json('$.errorMessage')) # JSON return object
                headers:
                  Content-Type: "'application/json'"


output

> serverless deploy --verbose

Serverless: DOTENV: Loading environment variables from .env:
Serverless:      - SAMPLE_ENV_VAR
Serverless:      - SLS_DEBUG
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command generate-event
Serverless: Load command test
Serverless: Load command dashboard
Serverless: Load command output
Serverless: Load command output:get
Serverless: Load command output:list
Serverless: Load command param
Serverless: Load command param:get
Serverless: Load command param:list
Serverless: Load command studio
Serverless: Skipping variables resolution with old resolver (new resolver reported no more variables to resolve)
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Invoke webpack:validate
Serverless: Using configuration:
{
  "packager": "npm",
  "packagerOptions": {},
  "webpackConfig": "node_modules\\serverless-bundle/src/webpack.config.js",
  "includeModules": {
    "forceExclude": [
      "aws-sdk"
    ],
    "forceInclude": null,
    "packagePath": "package.json"
  },
  "keepOutputDirectory": false,
  "concurrency": 8
}
Serverless: Removing C:\Users\Administrator\Documents\ST\ST-Test-API\.webpack
Serverless: Individually packaging with concurrency at 8 entries a time.
Serverless: Invoke webpack:compile
Serverless: Bundling with Webpack...
Serverless: Invoke webpack:package
Serverless: Fetch dependency graph from C:\Users\Administrator\Documents\ST\ST-Test-API\package.json
Serverless: No external modules needed

zip error: Invalid command arguments (no such option: -)

 Error ---------------------------------------------------

  Error: Unexpected exit code from native zip: 16
   executed command 'zip --quiet --recurse-paths ..\post-asset.zip ./'
   executed in directory 'C:\Users\Administrator\Documents\ST\ST-Test-API\.webpack\post-asset'
      at ChildProcess.<anonymous> (C:\Users\Administrator\Documents\ST\ST-Test-API\node_modules\bestzip\lib\bestzip.js:86:13)
      at ChildProcess.emit (events.js:314:20)
      at ChildProcess.EventEmitter.emit (domain.js:483:12)
      at maybeClose (internal/child_process.js:1021:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          win32
     Node Version:              12.19.0
     Framework Version:         2.51.0
     Plugin Version:            5.4.3
     SDK Version:               4.2.3
     Components Version:        3.13.3

Installed version

>serverless --version
Framework Core: 2.51.0
Plugin: 5.4.3
SDK: 4.2.3
Components: 3.13.3

Most helpful comment

I was able to solve it. If you look at my .yml, you see I have serverless-bundle which has serverless-webpack as a dependency.
I reverted to an older version of serverless-webpack:

npm i [email protected]

Mind you I am not the only one having problems with the newer versions of serverless-webpack!
Look at https://github.com/AnomalyInnovations/serverless-bundle/issues/228

All 5 comments

I was able to solve it. If you look at my .yml, you see I have serverless-bundle which has serverless-webpack as a dependency.
I reverted to an older version of serverless-webpack:

npm i [email protected]

Mind you I am not the only one having problems with the newer versions of serverless-webpack!
Look at https://github.com/AnomalyInnovations/serverless-bundle/issues/228

same problem to me! thank you for the solution worked well!

@adir1661 are you also running the deploy command on Windows?

@adir1661 are you also running the deploy command on Windows?

yes exactly windows

Can you create a small projet on a github repo to reproduce the error? So I can try to find out what could be wrong. Thanks 🙏

Was this page helpful?
0 / 5 - 0 ratings