Skip to content

Getting error since upgrading to middy 3.x #182

Open
@TPME

Description

@TPME

Hi, I just upgraded middy to version 3 as well as your plugin. Unfortunately I get the following error now:

2022-10-12T15:37:36.879Z	undefined	ERROR	Uncaught Exception 	
{
    "errorType": "TypeError",
    "errorMessage": "cache is not a function",
    "stack": [
        "TypeError: cache is not a function",
        "    at applyCacheOption (webpack-internal:///3705:180:49)",
        "    at middify (webpack-internal:///3705:83:28)",
        "    at eval (webpack-internal:///3381:6:46)",
        "    at Object.3381 (/var/task/src/modules/posts/postsRoute.js:212:1)",
        "    at __webpack_require__ (/var/task/src/modules/posts/postsRoute.js:432:42)",
        "    at /var/task/src/modules/posts/postsRoute.js:443:37",
        "    at Object.<anonymous> (/var/task/src/modules/posts/postsRoute.js:448:12)",
        "    at Module._compile (node:internal/modules/cjs/loader:1105:14)",
        "    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)",
        "    at Module.load (node:internal/modules/cjs/loader:981:32)",
        "    at Function.Module._load (node:internal/modules/cjs/loader:822:12)",
        "    at Module.require (node:internal/modules/cjs/loader:1005:19)",
        "    at require (node:internal/modules/cjs/helpers:102:18)",
        "    at _tryRequireFile (file:///var/runtime/index.mjs:869:37)",
        "    at _tryRequire (file:///var/runtime/index.mjs:919:25)",
        "    at _loadUserApp (file:///var/runtime/index.mjs:945:22)",
        "    at Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:976:27)",
        "    at start (file:///var/runtime/index.mjs:1137:42)",
        "    at file:///var/runtime/index.mjs:1143:7",
        "    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)",
        "    at async Promise.all (index 0)",
        "    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)",
        "    at async loadESM (node:internal/process/esm_loader:88:5)",
        "    at async handleMainPromise (node:internal/modules/run_main:61:12)"
    ]
}

What gives? I have not changed the way I use your plugin, which is basically:

import * as cache from "@schibsted/middy-caching-headers";

let middifiedHandler = middy(handler);

const cacheTime = 10 * 60;

middifiedHandler = middifiedHandler.use(
  cache({
    success: {
      directive: `public,stale-while-revalidate=${
        cacheTime / 10
      },stale-if-error=${cacheTime}`,
      serverTime: cacheTime,
      clientTime: cacheTime,
    },
    errors: {
      default: {
        directive: `public,stale-while-revalidate=${
          cacheTime / 10
        },stale-if-error=${cacheTime}`,
        serverTime: cacheTime / 10,
        clientTime: cacheTime / 10,
      },
      404: {
        directive: `public,stale-while-revalidate=${
          cacheTime / 10
        },stale-if-error=${cacheTime}`,
        serverTime: cacheTime,
        clientTime: cacheTime,
      },
    },
  })
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions