Package 'individually=true' not working when setup at function level and 'false' at service level
Hello,
I got an issue with the package 'individually' not working. I have setup a simple project to easily test it:
serverless.yml:
service: sls-ts-package-individually
frameworkVersion: "3"
configValidationMode: error
plugins:
- serverless-plugin-typescript
provider:
name: aws
runtime: nodejs18.x
package:
individually: false
patterns:
- src/**
functions:
one:
handler: src/main.handler1
two:
handler: src/main.handler2
three:
handler: src/main.handler3
package:
individually: true
patterns:
- "!src/not_included_in_3"
package.json
{
"name": "test-sls-ts-package-individually",
"version": "1.0.0",
"description": "To test package individually",
"license": "UNLICENSED",
"private": true,
"scripts": {
"build": "tsc"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.131",
"@types/node": "^18.11.9",
"serverless": "^3.38.0",
"serverless-plugin-typescript": "^2.1.5",
"typescript": "~4.7.4"
},
"dependencies": {}
}
src/main.ts
import { Handler } from "aws-lambda";
export const handler1: Handler = async () => {
console.info("Hello function one!");
};
export const handler2: Handler = async () => {
console.info("Hello function two!");
};
export const handler3: Handler = async () => {
console.info("Hello function three!");
};
- It also need a file named
src/not_included_in_3
Then when I type sls package, I got this error:
Running "serverless" from node_modules
Packaging sls-ts-package-individually for stage dev (us-east-1)
Compiling with Typescript...
Using local tsconfig.json - tsconfig.json
Typescript compiled.
Warning: Package patterns at function level are only applicable if package.individually is set to true at service level or function level in serverless.yaml. The framework will ignore the patterns defined at the function level and apply only the service-wide ones.
Environment: linux, node 18.19.0, framework 3.38.0 (local) 3.10.2v (global), plugin 7.2.0, SDK 4.5.1
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues
Error:
Error: Error: Error: ENOENT: no such file or directory, open '/home/user/git/test/test-sls-ts-package-individual/.build/.serverless/three.zip' encountered during hash calculation for provided filePath: /home/user/git/test/test-sls-ts-package-individual/.build/.serverless/three.zip
at ReadStream.<anonymous> (/home/user/git/test/test-sls-ts-package-individual/node_modules/serverless/lib/plugins/aws/package/lib/get-hash-for-file-path.js:23:13)
at ReadStream.emit (node:events:517:28)
at ReadStream.emit (node:domain:489:12)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
If I disable the plugin serverless-plugin-typescript it's working fine. And I got 2 package in .serverless directory without error:
sls-ts-package-individually.zipthree.zip
Can this be fixed?
Thank you, Bruno
just watching, have similar issue
@bruno-xo7 I apologize, maybe it's wrong, but according to the documentation on the service level individually should be true:
...
package:
individually: true
...
and remove individually from function level:
...
three:
handler: src/main.handler3
package:
patterns:
- "!src/not_included_in_3"
...
@bruno-xo7 But in my case I have the same warning as you, but I configure package on service level, and don't use individual at all
...
package:
excludeDevDependencies: true
patterns:
- '!node_modules/serverless*/**'
- '!node_modules/aws_sdk/'
- '!package-lock.json'
...
VSCode plugin says (regarding the same documentation article mentioned in the comment above) that the package block should be on provider level ((
Hello @a-khalilov,
What you describe, it's to have 3 individual packages (in my example), one for each function. My problem is not this case, I want to have one 'global' (a.k.a. not individual) package for functions 'one' and 'two' and one individual package for the function 'three'. This is why I set the 'individually' at false at service level and true at the function 3 level.
@bruno-xo7 I see. You're right, I didn't understand your case correctly. But I can confirm, that with my config I tried to reproduce your case and got 2 packages and the error. I'm guessing that the error makes your pipeline fail. Because I've seen both packages and they're correct
Correct @a-khalilov, It's failed at the package step and indeed the deploy is not launched because of the fail
@bruno-xo7 I got your problem. Had something similar with other serverless plugins. I use some pipes as a workaround, something like
sls package | tee /dev/tty | grep -q 'anything of command's output that you would like to use as a condition' && exit 1
I'm sure you found a workaround, but anyway maybe it'll be useful for others
Cheers!