agutoli / serverless-layers

Serverless.js plugin implementing AWS Lambda Layers, reducing lambda size, warm-up, and deployment time.
MIT License
229 stars 53 forks source link

Fails to load modules from layer after upgrading to sls v3 #121

Closed orr-levinger closed 1 year ago

orr-levinger commented 1 year ago

I was using the plugin with no issues. but after upgrading my sls version to 3.24.1 i started getting module not found error

2022-11-20T13:16:16.252Z    undefined   ERROR   Uncaught Exception  {
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module '@google-cloud/dialogflow-cx'\nRequire stack:\n- /var/task/src/functions/events/on-message-event.js\n- /var/runtime/UserFunction.js\n- /var/runtime/Runtime.js\n- /var/runtime/index.js",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module '@google-cloud/dialogflow-cx'",
        "Require stack:",
        "- /var/task/src/functions/events/on-message-event.js",
        "- /var/runtime/UserFunction.js",
        "- /var/runtime/Runtime.js",
        "- /var/runtime/index.js",
        "    at _loadUserApp (/var/runtime/UserFunction.js:225:13)",
        "    at Object.module.exports.load (/var/runtime/UserFunction.js:300:17)",
        "    at Object.<anonymous> (/var/runtime/index.js:43:34)",
        "    at Module._compile (internal/modules/cjs/loader.js:1085:14)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
        "    at Module.load (internal/modules/cjs/loader.js:950:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:790:12)",
        "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)",
        "    at internal/main/run_main_module.js:17:47"
    ]
}

I see that the layer is really not installed after upgrading to sls v3 image

i have this package.json for this lib:

{
  "name": "blind-chat-backend-side",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "@google-cloud/dialogflow-cx": "^2.14.0",
    "firebase-admin": "^10.0.1"
  },
  "author": "",
  "license": "ISC"
}

and this sls.yml configuration:

  serverless-layers:
      - common:
          dependenciesPath: ./package.json
          layersDeploymentBucket: ${self:custom.base}-layers
      - dialogflow:
          functions:
            - onMessageEvent
          dependenciesPath: /package-dialogflow.json
          layersDeploymentBucket: ${self:custom.base}-layers

this is the lambda definition:

  onMessageEvent:
      handler: src/functions/events/on-message-event.handler
      timeout: 180
      provisionedConcurrency: 1

any advice?

bmwoolf commented 1 year ago

same problem, with node-fetch. literally even put the binary it in the same folder

agutoli commented 1 year ago

Hey @orr-levinger, sorry for late reply. I've done some test but couldn't reproduce that issue. It seems to be working for me. Maybe you was using a broken serverless-layers version.

Screen Shot 2023-01-02 at 8 41 15 pm Screen Shot 2023-01-02 at 8 41 55 pm