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)
If I am getting it correctly, your puppeteer lives inside
node_modulesin your ZIP. Serverless core, by default, brings everything in yournode_modulesinto the final archive.Our package installer, i.e. the
noInstalloption, doesn’t matter here because if youradblocker-puppeteerlives in yourdependencies, itspeerDependenciesare in turn installed along with it.You may try the followings,
puppeteerin yourdevDependencies, and make sure you do not setfalsetopackage.excludeDevDependencies. This may overrides thepeerDependenciesrelation inadblocker-puppeteerand tricks Serverless core to exclude it in the packing stage.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:
@j0k3r @vicary I’ve created minimal reproducible repo. Could you please check?
git clone https://github.com/andrew-ignatiev/serverless-typeormcd serverless-typeormnvm use 14npm cinpm run sls:package -- -s devand wait 10-20 minutescd .serverlessmkdir ./resunzip http-v1.zip -d ./rescd ./resnpm list typescript