memorystore icon indicating copy to clipboard operation
memorystore copied to clipboard

Class constructor LRUCache cannot be invoked without 'new'

Open mattanimation opened this issue 3 years ago • 3 comments

node version: v14.15.0 via nvm version: 1.6.4

I get this error when attempting to use the memorystore.

Class constructor LRUCache cannot be invoked without 'new' {
  "stack": "TypeError: Class constructor LRUCache cannot be invoked without 'new'\n    at new MemoryStore (/node_modules/memorystore/lib/memorystore.js:78:1)

I did add the new on line 78 and re-built and it does fix the error

my code sample

import session from 'express-session';
import createMemoryStore from 'memorystore';
...
const MemoryStore = createMemoryStore(session);
...

const expStoreConfig: session.SessionOptions = {
        secret: environment.session_secret,
        cookie: { maxAge: 86400000 },
        store: new MemoryStore({
          checkPeriod: 86400000
        }),
        resave: false,
        saveUninitialized: true
    };

change to line: 78 this.store = new LRU(this.options)

I could create a PR but the fix is so tiny, it might be faster on your end?

Note:

  • I am using nx and yarn to build and manage my packages

mattanimation avatar Mar 06 '21 09:03 mattanimation

did you yarn install or npm install? what version of lru-cache did npm bring in when you installed?

roccomuso avatar Mar 08 '21 18:03 roccomuso

I did use yarn install to fetch it and it looks like it went with 6.0.0. I did notice on another thread for lru-cache that they had mentioned an update that now requires the new keyword. I noticed the version reference in this package.json is ^4.0.3 so maybe its just an update the version and adding the new on line 78

mattanimation avatar Mar 08 '21 20:03 mattanimation

if you use the yarn install command the version installed should be 4.1.5 as stated in yarn.lock. So I don't know how you possibly fetched 6.0.0.

roccomuso avatar Mar 08 '21 22:03 roccomuso