We are using the following configuration for the package:
package:
exclude:
- 'node_modules/**'
This is similar to the example in the docs, but it seems, it does not work: the node_modules directory is always included. The problem has already been reported a few times
No update from anyone here. However, I just tested a different set up. With the script from the original question, we make sure that only the node modules from âproductionâ are used (remove the --ignore scripts, if this is required by some packages).
Now, we just exclude the original source and test folders:
Iâm having the same problem. The way excludes/includes and individual packaging work donât seem to line up with the documentation. Iâm currently trying to exclude all node modules from an individually packaged function. However, the only way it will work is if I use the global package individually setting. If the global setting is not used the function package settings are ignored and everything is included in the package.
Donât you need to exclude everything first than begin to include? This is what worked for me (I manage functions individually but it may not matter):
Serverless changed the way it handled dependencies a few releases ago. Previously it uploaded everything from node_modules which included development dependencies. There were a number of solutions around this but theyâre all redundant now. Serverless will automatically exclude the development dependencies (and their dependencies) from the zip file. It looks like this change means you can no longer exclude packages from the node_modules directory manually.
Good to know. I did not see this at all. Just checked with the documentation ⌠it says this in the end (Development Dependencies)
Serverless will auto-detect and exclude development dependencies based on the runtime your service is using.
This ensures that only the production relevant packages and modules are included in your zip file. Doing this drastically reduces the overall size of the deployment package which will be uploaded to the cloud provider.
It might be good to update the first example which still uses include/exclude on node_modules.
Sounds good. I did not understand it this way. For me, the include-only should work like a whitelist. However, it seems I just misunderstood the documentation. Thank you for clarifying this!
Make sure itâs not a webpack issue. If youâre using serverless-webpack in your serverless.yml to transpile code, it will be bundled into a .webpack dir (or some other temporary/intermediary dir) and itâs from there that serverless will try to create a CloudFormation package. So if youâre trying to include/exclude stuff from the root of your project dir, then youâre prone to get confused/frustrated. I solved my particular problem by specifying what files/dir I wanted to copy over in the webpack.config.js to .webpack using a webpack plugin called copy-webpack-plugin. Syntax:
But node_modules are still included no matter what but itâs probably good practice to include â!node_modules/**â in case the code changes in the future.
Same problem here. The âpackageâ command works in general but not in function scope. Or to be more precise it does, because the âartifactâ child element is recognized and evaluaed only âincludeâ and âexcludeâ are just skipped.
Are there any news on that topic? In theory it does not sound like a big problem, more like a minor bug.