serverless-webpack: Unable to exclude package from being bundled

This is a Bug Report

Description

What went wrong?

I am using the puppeteer package, and it creates inside a .local-chromium folder during package installation.

This package and .local-chromium folder are being packaged together into the zip file which end up being 352Mb.

What did you expect should have happened?

Package puppeteer should not be present in the resulting zip node_modules/ folder.

What was the config you used?

See config and full reproducible example in https://github.com/huksley/puppeteerless/blob/main/serverless.yml

What stacktrace or error message from your provider did you see?

I am getting very slow upload speed and error that unpacked size exceeds 200Mb.

Additional Data

  • Node and NPM version you’re using: NodeJS v16.16.0 NPM v8.11.0
  • Serverless-Webpack Version you’re using: "serverless-webpack": "5.8.0"
  • Webpack version you’re using: "webpack": "^5.72.1", "webpack-node-externals": "^3.0.0"
  • Serverless Framework Version you’re using: "serverless": "^3.21.0"
  • Operating System: Mac OS X 12.5
  • Stack Trace (if available): N/A

Reproducing

> git clone https://github.com/huksley/puppeteerless
> cd puppeteerless
> npm install
> npm run package
> ls -lah .serverless
total 843384
drwxr-xr-x   8 ruslan  staff   256B Aug 11 01:03 .
drwxr-xr-x  19 ruslan  staff   608B Aug 11 01:03 ..
-rw-r--r--   1 ruslan  staff    50M Aug 11 01:03 chrome.zip
-rw-r--r--   1 ruslan  staff   2.2K Aug 11 01:03 cloudformation-template-create-stack.json
-rw-r--r--   1 ruslan  staff   9.5K Aug 11 01:03 cloudformation-template-update-stack.json
-rw-r--r--   1 ruslan  staff   8.9M Aug 11 01:03 fonts.zip
-rw-r--r--   1 ruslan  staff   352M Aug 11 01:03 puppeteerless.zip
-rw-r--r--   1 ruslan  staff    18K Aug 11 01:03 serverless-state.json

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 2
  • Comments: 21 (4 by maintainers)

Most upvoted comments

If I am getting it correctly, your puppeteer lives inside node_modules in your ZIP. Serverless core, by default, brings everything in your node_modules into the final archive.

Our package installer, i.e. the noInstall option, doesn’t matter here because if your adblocker-puppeteer lives in your dependencies, its peerDependencies are in turn installed along with it.

You may try the followings,

  1. Explicitly install puppeteer in your devDependencies, and make sure you do not set false to package.excludeDevDependencies. This may overrides the peerDependencies relation in adblocker-puppeteer and tricks Serverless core to exclude it in the packing stage.
  2. Excluding it via package.patterns !node_modules/puppeteer/**.

@collierrgbsitisfise thanks I already doing it and use esbuild to trace dependencies and it works pretty well

Why is this marked as “Awaiting reply”? All replies and reproducible repo has been given.

Temporary workaround for short term in serverless.yml:

....
plugins:
  - serverless-webpack
...
  - serverless-scriptable-plugin
...
  scriptable:
    # add custom hooks
    hooks:
      after:package:createDeploymentArtifacts: 'find ./.serverless -name "*.zip" -exec zip --delete {} "node_modules/ts-node/*" "node_modules/typescript/*" "node_modules/aws-sdk/*" \;'
...

@j0k3r @vicary I’ve created minimal reproducible repo. Could you please check?

  • git clone https://github.com/andrew-ignatiev/serverless-typeorm
  • cd serverless-typeorm
  • nvm use 14
  • npm ci
  • npm run sls:package -- -s dev and wait 10-20 minutes
  • cd .serverless
  • mkdir ./res
  • unzip http-v1.zip -d ./res
  • cd ./res
  • npm list typescript