Layer Service: No file matches include / exclude patterns

See original GitHub issue

This is a Bug Report

Description

  • What went wrong? When I tried to make a layer with serverless and tries to deploy the new service I got the following error No file matches include / exclude patterns
  • What did you expect should have happened? I have expected to deploy the layer normally like any other service
  • What was the config you used? Here is the service file that I’m using
service: psycopg2 

provider:
  name: aws

layers:
  psycopg2:
    buildScript: ./build.sh
    path: layer
    compatibleRuntimes:
      - python3.6
    allowedAccounts:
      - '*'
  • What stacktrace or error message from your provider did you see?
ServerlessError: No file matches include / exclude patterns
    at globby.then.allFilePaths (/usr/local/lib/node_modules/serverless/lib/plugins/package/lib/packageService.js:234:13)
From previous event:
    at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:90:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
From previous event:
    at Package.resolveFilePathsLayer (/usr/local/lib/node_modules/serverless/lib/plugins/package/lib/packageService.js:190:48)
    at Package.packageLayer (/usr/local/lib/node_modules/serverless/lib/plugins/package/lib/packageService.js:152:17)
    at packagePromises.concat._.map.layerName (/usr/local/lib/node_modules/serverless/lib/plugins/package/lib/packageService.js:71:19)
    at arrayMap (/usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:639:23)
    at Function.map (/usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:9556:14)
    at Package.packageService (/usr/local/lib/node_modules/serverless/lib/plugins/package/lib/packageService.js:65:48)
From previous event:
    at Object.package:createDeploymentArtifacts [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/package/package.js:64:10)
    at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:407:55)
From previous event:
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:407:22)
    at PluginManager.spawn (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:425:17)
    at Deploy.BbPromise.bind.then (/usr/local/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:117:50)
From previous event:
    at Object.before:deploy:deploy [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:107:10)
    at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:407:55)
From previous event:
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:407:22)
    at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:438:17)
    at variables.populateService.then.then (/usr/local/lib/node_modules/serverless/lib/Serverless.js:114:33)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:120:23)
From previous event:
    at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:101:6)
    at serverless.init.then (/usr/local/lib/node_modules/serverless/bin/serverless:43:28)
    at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:111:16
    at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:45:10
    at FSReqWrap.oncomplete (fs.js:141:20)
From previous event:
    at initializeErrorReporter.then (/usr/local/lib/node_modules/serverless/bin/serverless:43:6)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:120:23)
From previous event:
    at /usr/local/lib/node_modules/serverless/bin/serverless:28:46
    at Object.<anonymous> (/usr/local/lib/node_modules/serverless/bin/serverless:67:4)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:282:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

Similar or dependent issues:

Additional Data

  • Serverless Framework Version you’re using: 1.38.0
  • Operating System: 10.14.3
  • Stack Trace:
  • Provider Error messages:

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:24
  • Comments:35 (6 by maintainers)

github_iconTop GitHub Comments

37reactions
dchao19commented, Jul 29, 2019

I had the same problem. I had ./** specified in the root (i.e top level - not the individual layer include/exclude) package:exclude option and I kept running into the No file matches include / exclude patterns bug.

I did some digging and it turns out that the error occurs while packaging the layer, not the functions. Even though the matching of the patterns occurs against the individual layer directory itself, Serverless also runs all of the layer files to package against the same patterns of the root service. Here’s an example:

Let’s say your serverless.yml has the following, root-level, package section:

package:
  individually: true
  exclude: 
    - ./**
  include:
    - ./functions/**/*

And your layers are structured in the service like this:

serverless.yml
layers/
└─ node_modules
       └─ package-1/
       └─ package-2/
       └─ package-3/
functions/

When serverless is packaging your layer, it is only checking the files in the layers directory, so it is checking:

layers/node_modules/package-1/**
layers/node_modules/package-2/**

But serverless is checking those files against the patterns specified in the root package:exclude and because ./** matches every file and the include-pattern ./functions/**/* matches none, no files are actually included in the layer, which causes the error.

You can fix this (if you want to add everything in your layer directory to the package) by adding an additional package:include section to your layer configuration. For instance:

layers:
  nodeModules:
    package:
      include:
        - ./**

Because the layers:nodeModules:package:include is not checked when packaging a function or an entire service, adding the ./** include to the layer only impacts how the layer is packaged. Serverless “scopes” the packaging of the layer to be checking files that are only in the layers:nodeModules:path so other packaging operations are not impacted.

17reactions
dogzzdogzzcommented, Mar 11, 2019

My exclude/include in serverless.yml as below worked well before,

package:
  exclude:
    - ./**
  individually: true
functions:
  hello:
    package:
      include:
      - hello/**

until I added layers, I got " No file matches include / exclude patterns" error

layers:
  foo:
    path: bar
Read more comments on GitHub >

github_iconTop Results From Across the Web

Serverless error - No file matches include / exclude patterns
serverless is checking those files against the patterns specified in the root package:exclude and because./** matches every file and the include ...
Read more >
Serverless-python-layers: No file matches include / exclude ...
I am trying some skeleton deployment using python. Here is my serverless.yaml My folder structure is serverless-test |_lambdas ...
Read more >
Serverless - Include/Exclude
As you would have guessed, you can specify files and folders that you want to exclude from the deployment build using the 'exclude'...
Read more >
Serverless Deploy pipe file not found include / exclude
ServerlessError: No file matches include / exclude patterns. I can deploy this from local no problem, I have no errors, but when I...
Read more >
Serverless-jetpack - npm.io
Service level package.include|exclude patterns are applied at the layers. ... {js,mjs} to then trace, and will throw an error if no matching files...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found