jaredwray / cacheable

Caching for Nodej.js - the goal with the Cacheable Project is to provide a robust, scalable, and maintained set of caching packages

Home Page:https://cacheable.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Can't find ./stores/memory [undefined]

cygomez opened this issue · comments

I am trying to run a unit that utilizes node-cache-manager, however I keep receiving this error from Chrome about being unable to find './stores/memory'... Need some assistance to resolve this issue.

Chrome 55.0.2883 (Mac OS X 10.11.6) Queue Manager encountered a declaration exception FAILED
	Error: Can't find ./stores/memory [undefined] (required by /Users/cyrus_gomez-alcala/Development/CloneDir/ced-event-queue-processor/node_modules/cache-manager/lib/caching.js)
	    at require (node_modules/karma-typescript/lib/commonjs.js:13:23)
	    at node_modules/karma-typescript/lib/commonjs.js:18:24
	    at Object.caching (/var/folders/jd/06g9g2555_1fxy7zv7w3b0j00000gp/T/karma-typescript-bundle-17671uiqYs3E3lhyT.js:78496:22)
	    at Suite.describe (test/spec/manager/queueManger.spec.ts:28:15 <- test/spec/manager/queueManger.spec.js:25:32)
	    at Object.global.wrappers./Users/cyrus_gomez-alcala/Development/CloneDir/ced-event-queue-processor/test/spec/manager/queueManger.spec.ts.../../../src/manager/queueManager (test/spec/manager/queueManger.spec.ts:26:0 <- test/spec/manager/queueManger.spec.js:23:1)
	    at require (node_modules/karma-typescript/lib/commonjs.js:17:25)
	    at node_modules/karma-typescript/lib/commonjs.js:32:9
	    at Array.forEach (native)
	    at node_modules/karma-typescript/lib/commonjs.js:31:40
	    at node_modules/karma-typescript/lib/commonjs.js:34:3`

This line produces the error

let test = caching({store : 'memory', max: 1, ttl: 60}); 

queueManager.spec.ts

import QueueManager from '../../../src/manager/queueManager';
import { caching } from 'cache-manager';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 999999;

describe("Queue Manager", () => {
    let connection:any;
    let test = caching({store : 'memory', max: 1, ttl: 60});

    console.log("test " + test);

    beforeAll( (done) => {
        connection = QueueManager.connect(queueConfig);
        done();
    });


    it("Create Connection to Rabbit MQ", (done) => {
       expect(connection).not.toBe(null);
       done();
    });

});

KARMA.CONF.JS

module.exports = function(config) {
    config.set({
      basePath: '.',
      karmaTypescriptConfig: {
        bundlerOptions: {
          exclude: ["express"]
        },
        compilerOptions: {
          "target": "es6",
          "module": "commonjs",
          "moduleResolution": "node",
          "removeComments": false,
          "noImplicitAny" : false,
          "sourceMap": true,
          "typeRoots": [
            "node_modules/@types/"
          ],
          "compileOnSave": true
        },
        include: [
          "src/**/*.ts",
          "test/spec/**/*.spec.ts"
        ],
        exclude: ["node_modules", "src/router/queueProcessorRouters.ts"],
        reports: {
          "html": "coverage",
          "text-summary": ""
        },
        transformPath: function(filepath) {
          return filepath.replace(/\.(ts|tsx)$/, ".js");
        },
      },
      frameworks: ["jasmine", "karma-typescript"],
      files: [
          { pattern: "src/**/*.ts" },
          { pattern: "test/spec/**/*.spec.ts" }
      ],
      exclude:["node_modules", "src/router/queueProcessorRouters.ts"],
      preprocessors: {
          "src/config/*.ts": ["karma-typescript"],
          "src/manager/*.ts": ["karma-typescript"],
          "src/messageProcessor/*.ts": ["karma-typescript"],
          "src/service/*.ts": ["karma-typescript"],
          "src/util/*.ts": ["karma-typescript"],
          "test/spec/**/*.spec.ts": ["karma-typescript"]
      },
      mime: {
          "text/x-typescript":["ts","tsx"]
      },
      reporters: ["progress", "kjhtml", "karma-typescript"],
      browsers: ["Chrome"],
      logLevel: config.LOG_DEBUG,
    });
};

PACKAGE.JSON

"dependencies": {
    "@types/amqplib": "^0.5.0",
    "@types/cache-manager": "^1.2.4",
    "@types/express": "^4.0.34",
    "@types/jasmine": "^2.5.40",
    "@types/node": "^6.0.52",
    "@types/request": "0.0.36",
    "amqplib": "^0.5.1",
    "cache-manager": "^2.2.0",
    "express": "^4.14.0",
    "fibonacci": "^1.6.4",
    "file-stream-rotator": "0.0.7",
    "morgan": "^1.7.0",
    "pm2-check-express": "^0.1.0",
    "request": "^2.79.0",
    "typescript": "^2.1.4",
    "uuid": "^3.0.1",
    "winston": "2.3.0"
  },
  "devDependencies": {
    "grunt": "^1.0.1",
    "grunt-auto-install": "^0.3.1",
    "grunt-contrib-clean": "^1.0.0",
    "grunt-contrib-copy": "^1.0.0",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-karma": "^2.0.0",
    "grunt-ts": "^6.0.0-beta.3",
    "jasmine-core": "^2.5.2",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-jasmine": "^1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-phantomjs-launcher": "^1.0.2",
    "karma-typescript": "^2.1.6",
    "karma-typescript-preprocessor": "^0.3.1"
  }
}

Hi. I think you might have to import the memory module manually and then pass it into the store. Something like:

// adjust the path to the real path for you:
import memoryStore from '../../../node_modules/cache-manager/lib/stores/memory';
let test = caching({store : memoryStore, max: 1, ttl: 60});

Hope that helps.

@BryanDonovan thank you! this solved my issue.