serverless / serverless-plugin-typescript

Serverless plugin for zero-config Typescript support
MIT License
783 stars 223 forks source link

ServerlessError: No file matches include / exclude patterns when using Layers #240

Closed WeaponizedLego closed 2 years ago

WeaponizedLego commented 3 years ago

Im experiencing No FIle Matches include / exclude patterns when using the new AWS Lambda layers

here is the last part of the logs

serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Excluding development dependencies...
Serverless: Excluding development dependencies...

 Serverless Error ----------------------------------------

  ServerlessError: No file matches include / exclude patterns
      at /Users/glen/_code/ts-ooono-backend/node_modules/serverless/lib/plugins/package/lib/packageService.js:263:13
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async /Users/glen/_code/ts-ooono-backend/node_modules/serverless/lib/plugins/package/lib/packageService.js:91:9
      at async Promise.all (index 2)
      at async Package.packageService (/Users/glen/_code/ts-ooono-backend/node_modules/serverless/lib/plugins/package/lib/packageService.js:95:5)

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

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              16.0.0
     Framework Version:         2.47.0 (local)
     Plugin Version:            5.4.0
     SDK Version:               4.2.3
     Components Version:        3.12.0

and this is my layers and plugins

##
## Package settings
##
package:
  excludeDevDependencies: true
  individually: true
  patterns:
    - '!node_modules'
    - '!layers'

##
## Serverless plugins
## TODO: figure out how to have serverless-plugin-typescript in and still deploy as it doesn't build without it
plugins:
  - serverless-plugin-typescript
  - serverless-offline

##
## Layers
##
layers:
  NodeModules:
    path: layers
#    name: NodeModules
    name: ${sls:stage}-NodeModules
    compatibleRuntimes:
      - nodejs14.x
    package:
      patterns:
        - '**/**'
    description: ---
    retain: false # Delete layers once a new one of same name is uploaded

##
## FUNCTIONS
##
functions:
  # GET /hello
  hello:
    handler: ./src/functions/helloworld/index.handler
    events: # The events that trigger this function
      - http:
          path: ts-ooonoBackend/helloworld
          method: get
    layers:
      - { Ref: NodeModulesLambdaLayer }
    package:
      patterns:
        - 'src/functions/helloworld/**'
  goodbye:
    handler: ./src/functions/goodbye/index.handler
    events: # The events that trigger this function
      - http:
          path: ts-ooonoBackend/goodbye
          method: post
    layers:
      - { Ref: NodeModulesLambdaLayer }
    package:
      patterns:
        - 'src/functions/goodbye/**'
medikoo commented 3 years ago

Will be fixed with #243

pgrzesik commented 3 years ago

After doing research as part of https://github.com/serverless/serverless/issues/9873 I've realised that layers are generally not supported by this plugin so this issue should still be open.

The general problem here lies in the fact that when packaging files for layers, layer.path property is used as a prefix https://github.com/serverless/serverless/blob/f096440440dfb2339b4fd1ae1ecbca3b59fb4805/lib/plugins/package/lib/packageService.js#L272 however, the logic in the plugin changes the serviceDir to point to .build directory, which means that in most scenarios nothing will be available under serviceDir/<layer.path>.

abdullahmonoar commented 2 years ago

@pgrzesik any workarounds you know of other than webpacking the ts files ourselves?

pgrzesik commented 2 years ago

Hello @abdullahmonoar - the only workaround I know is switching to serverless-webpack or serverless-jetpack :(

alexandrubese commented 2 years ago

I can also confirm it works by using serverless-jetpack

alexandrubese commented 2 years ago

Any timeframe for the issue create above ^ ?

medikoo commented 2 years ago

@alexandrubese PR's welcome!

raiseandfall commented 2 years ago

@medikoo this looks old, but that seems to be addressing the issue: https://github.com/serverless/serverless-plugin-typescript/pull/128

medikoo commented 2 years ago

@raiseandfall great thanks for pointing. I've reached out to author of the PR to eventually update it so it's in sync with master

mmeyers-xomly commented 2 years ago

Since there wasn't any movement on this from the original author, I updated https://github.com/serverless/serverless-plugin-typescript/pull/128 and submitted it again which fixes this issue https://github.com/serverless/serverless-plugin-typescript/pull/267

@medikoo if you could take a look, I'd love to get this merged so layers work :) Thanks!

mmeyers-xomly commented 2 years ago

So the above PR fixes part of the issue, but not fully. It seems this only helps if the thing you want to put in a layer is something that would be packaged by this plugin. However, if it's an external file that wouldn't be included in the TS build, this is still broken with the same error.

micheleangioni commented 2 years ago

We've also been hit by this problem, any update?

micheleangioni commented 2 years ago

It seems we have the PR: https://github.com/serverless/serverless-plugin-typescript/pull/267

tachang commented 1 year ago

So the above PR fixes part of the issue, but not fully. It seems this only helps if the thing you want to put in a layer is something that would be packaged by this plugin. However, if it's an external file that wouldn't be included in the TS build, this is still broken with the same error.

I just ran into this and feel like it the commit needs to be reverted. I'm not sure exactly what case allows it to succeed. Is it checking for patterns: include because that is deprecated in serverless v3.

leonardoviada commented 1 year ago

@tachang any clue on how to tackle the problem in some way? I have a module in src/layer/shared/nodejs/node_modules/myd-api-utils/src/index.ts Locally everything works just fine but I cannot deploy it since it breaks during the CI process

walshe commented 1 year ago

@tachang any clue on how to tackle the problem in some way? I have a module in src/layer/shared/nodejs/node_modules/myd-api-utils/src/index.ts Locally everything works just fine but I cannot deploy it since it breaks during the CI process

same here

tttaisgt commented 10 months ago
image

the error still there 😢

cwbuecheler commented 7 months ago

Still seeing this error as of January 2024. Take the layer out of serverless.yml and the plugin works fine. Put the layer back in, and I get the same error reported above. Layer code in the YML looks like this:

layers:
  shared:
    name: hcapps-file-xfer-shared
    path: layers/shared
    description: Shared functionality for file transfer system
    compatibleRuntimes:
      - nodejs18.x
    compatibleArchitectures:
      - x86_64
    retain: false

I don't see anything in here that should be considered weird.

We've written our own build system for using TS with serverless but I was really hoping to ditch that and use the plugin. We make extensive use of shared layers though, so this is kind of important. I'll admit I could be screwing something up, but at this point I feel like I've tried every reasonable config option (and again, it works fine with the functions - it's just the layer that breaks)

Edit to add: there is nothing in /layers except a file called shared.ts