Tirke / node-cache-manager-stores

IORedis and Mongo store for node-cache-manager.
MIT License
29 stars 3 forks source link

Module not found while importing from node-cache-manager-ioredis #130

Closed vz-tl closed 1 year ago

vz-tl commented 1 year ago

I'm trying to use node-cache-manager-ioredis but struggling on importing from the package, as described in the readme:

import { ioRedisStore } from '@tirke/node-cache-manager-ioredis';

gives me the following error:

Error: Module not found: Error: Package path . is not exported from package [...]/node_modules/@tirke/node-cache-manager-ioredis (see exports field in [...]/node_modules/@tirke/node-cache-manager-ioredis/package.json)

The project is pretty much standard:

Any advice?

vz-tl commented 1 year ago

removing

"exports": {
    ".": {
      "require": "./src/index.js"
    }
  }

from the installed node module package.json would solve the issue, but this isn't really an option.

vz-tl commented 1 year ago

narrowing down a bit more: using require syntax works, but this doesn't fit for my project. So, updating the "exports" section in package.json to the following makes it work, when using import {...} from ...:

  "exports": {
    ".": {
      "require": "./src/index.js",
      "import": "./src/index.js"
    }

it would be great if using import syntax could also be properly supported.

Tirke commented 1 year ago

Hello @vz-tl, as you can see all the examples in docs are using the import syntax, so it works well, can you link your tsconfig or the way you are compiling / using your typescript?

vz-tl commented 1 year ago

This is an Angular Universal project, where your module is being imported in the express server part. The project is compiled via regular Angular server build target, based on webpack. Below related tsconfig.server.json output using tsc --showConfig:

{
    "compilerOptions": {
        "rootDir": ".",
        "baseUrl": ".",
        "target": "es2016",
        "module": "es2020",
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2018",
            "dom",
            "es2018.asynciterable"
        ],
        "moduleResolution": "node",
        "downlevelIteration": true,
        "sourceMap": true,
        "declaration": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "forceConsistentCasingInFileNames": true,
        "importHelpers": true,
        "skipLibCheck": true,
        "skipDefaultLibCheck": true,
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "allowJs": true,
        "paths": {
          // removed for brevity
        },
        "types": [
            "node"
        ],
        "outDir": "./out-tsc/server"
    },
    "files": [
        "./src/main.server.ts",
        "./server.ts",
         // rest removed for brevity
    ],
    "include": [
      // removed for brevity
    ],
    "exclude": [
        "jest.config.ts"
    ]
}
Tirke commented 1 year ago

@vz-tl Published 3.2.0 that should expose a CJS and an ESM build can you try with this new version?

vz-tl commented 1 year ago

@Tirke , works perfectly! Thx a lot!