Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashids under node: TypeError: hashids_1.default is not a constructor #443

Closed
Kachit opened this issue Jul 1, 2021 · 2 comments
Closed

Comments

@Kachit
Copy link

Kachit commented Jul 1, 2021

Hello. Maybe this question was answered. I use hashids with nestjs.
Deps list:

"dependencies": {
    "@nestjs/common": "^7.6.15",
    "@nestjs/config": "^0.6.3",
    "@nestjs/core": "^7.6.15",
    "@nestjs/platform-express": "^7.6.15",
    "@nestjs/swagger": "^4.8.0",
    "@nestjs/typeorm": "^7.1.5",
    "class-transformer": "^0.4.0",
    "class-validator": "^0.13.1",
    "dotenv": "^9.0.2",
    "env-var": "^7.0.1",
    "hashids": "^2.2.8",
    "lodash": "^4.17.21",
    "pg": "^8.6.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^6.6.6",
    "swagger-ui-express": "^4.1.6",
    "typeorm": "^0.2.32"
  }

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "lib": [
      "esnext",
      "esnext.bigint"
    ]
  }
}

Using in code

import Hashids from 'hashids';
...
@Get(':id')
  async findOne(@Param() params: FindGameParams, @Res() resp: Response) {
    const hashids = new Hashids();
    const value = hashids.encode([123456789]);
    console.log(value);
    const result = new Result();
    resp.status(HttpStatus.OK).json(result);
  }

And I have an error

TypeError: hashids_1.default is not a constructor

Please help.

@niieani
Copy link
Owner

niieani commented Jul 3, 2021

Try setting "esModuleInterop": true in tsconfig.json. Let me know if that doesn't work.

@Kachit
Copy link
Author

Kachit commented Jul 3, 2021

Yes this fix works correct. Thanks.

@niieani niieani changed the title Hashids + NestJS: TypeError: hashids_1.default is not a constructor Hashids under node: TypeError: hashids_1.default is not a constructor Jul 7, 2021
@niieani niieani pinned this issue Jul 7, 2021
@niieani niieani closed this as completed Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants