Skip to content

Mixing nodejs and python results in "ENOENT: no such file or directory, scandir '.serverless/requirement" #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gerbenoostra opened this issue Mar 16, 2022 · 2 comments

Comments

@gerbenoostra
Copy link

gerbenoostra commented Mar 16, 2022

I'm having lambda's of both the python and nodejs runtime. When building the dist, it results in the following error:

Serverless: Zipping required Python packages for ....
Serverless: Zipping required Python packages for src/func2...
 
 Exception -----------------------------------------------
 
  [OperationalError: ENOENT: no such file or directory, scandir '.serverless/requirements'] {
    cause: [Error: ENOENT: no such file or directory, scandir '.serverless/requirements'] {
      errno: -2,
      code: 'ENOENT',
      syscall: 'scandir',
      path: '.serverless/requirements'
    },
    isOperational: true,
    errno: -2,
    code: 'ENOENT',
    syscall: 'scandir',
    path: '.serverless/requirements'
  }
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              17.4.0
     Framework Version:         2.72.3 (local)
     Plugin Version:            5.5.4
     SDK Version:               4.3.2
     Components Version:        3.18.2

My serverless.yml contains:

plugins:
  - serverless-python-requirements

package:
  individually: true

custom:
  pythonRequirements:
    zip: true
    slim: true
    dockerizePip: non-linux
    usePoetry: false # <- can't be true with package:individually:true
    cacheLocation: ./.serverless-python-requirements-cache

provider:
  name: aws
  runtime: python3.8

functions:
  func1:
    handler: func1/index.main
    runtime: nodejs12.x
  func2:
    handler: handler.handle
    module: src/func2

My filetree structure is:

serverless.yml
package.json
yarn.lock
src
 - func1
    - index.js
 - func2
   - pyproject.tom
   - poetry.lock
   - handler
     - __init__.py 

I see a unzip_requirements.py being created in the project root

A quick check in the sourcecode at

return BbPromise.resolve(this.targetFuncs)
shows that it uses this.targetFuncs to determine for which functions to create a zip.

However, the inject.js filters the this.targetFuncs on the python runtime at

.

Shouldn't all occurrences of this.targetFuncs be replaced with one that filters on the runtime?

update 1:
Note that if I add a module to the js function, the mentioned scandir in the exception changes.
For example:

functions:
  func1:
    handler: func1/index.main
    runtime: nodejs12.x
    module: src/func1

results in scandir '.serverless/src/func1/requirements'

update 2:
As the module is used as the root dir, and requirements are only packed for functions with a python runtime, I can make sls dist succeed by assigning the python module dir to the nodejs function:

functions:
  func1:
    handler: func1/index.main
    runtime: nodejs12.x
    module: src/func2
@gerbenoostra
Copy link
Author

A possible workaround is to create an empty lambda:

#serverless.yml

functions:
  empty_python:
    handler: handler.handle
    description: "Empty project to trick python-requirements into preparing requirements."
    module: src/empty_python
  func1:
    handler: func1/index.main
    runtime: nodejs12.x
    module: src/empty_python
    package:
      patterns:
        - "src/func1/**"
  func2:
    handler: handler.handle
    module: src/func2
    package:
      patterns:
        - "src/func2/handler/**"
        - "src/func2/*.py

where src/empty_python only contains an empty requirements.txt.

Because it is specified first, it's requirements (which there are none) will be saved, and then reused by the nodejs functions.
Not pretty, but at least it works for now.

@gerbenoostra gerbenoostra changed the title Mixing js and python results in "ENOENT: no such file or directory, scandir '.serverless/requirement" Mixing nodejs and python results in "ENOENT: no such file or directory, scandir '.serverless/requirement" Mar 23, 2022
@OJFord
Copy link

OJFord commented Jun 17, 2022

Are you sure this doesn't still happen without node? I'm using just a single python function, and this happens as soon as I add zip: true (or layer: true which implicitly zips).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants