Stack Exchange
How to handle TypeError: Cannot read property 'plural' of undefined in javascript
When I develop apps in typescript,I compiled them to javascript inside the docker
The following is raw typescript
import { DefaultNamingStrategy, NamingStrategyInterface } from 'typeorm';
import { snakeCase } from 'typeorm/util/StringUtils';
import pluralize from 'pluralize';

export class CustomNamingStrategy extends DefaultNamingStrategy
  implements NamingStrategyInterface {
  tableName(targetName: string, userSpecifiedName: string): string {
    return userSpecifiedName
      ? userSpecifiedName
      : pluralize.plural(snakeCase(targetName));
  }


The following is compiled javascript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomNamingStrategy = void 0;
const typeorm_1 = require("typeorm");
const StringUtils_1 = require("typeorm/util/StringUtils");
const pluralize_1 = require("pluralize");
class CustomNamingStrategy extends typeorm_1.DefaultNamingStrategy {
    tableName(targetName, userSpecifiedName) {
        return userSpecifiedName
            ? userSpecifiedName
            : pluralize_1.default.plural(StringUtils_1.snakeCase(targetName));
    }

But when I tried to npm run start following error occured.
TypeError: Cannot read property 'plural' of undefined
    at CustomNamingStrategy.tableName (/src/dist/config/CustomNamingStrategy.js:11:35)

I installed both of @types/pluralize and pluralize as following package.json
"dependencies": {
    "@nestjs/common": "^7.0.0",
    "@nestjs/config": "^0.5.0",
    "@nestjs/core": "^7.0.0",
    "@nestjs/jwt": "^7.1.0",
    "@nestjs/passport": "^7.1.0",
    "@nestjs/platform-express": "^7.0.0",
    "@nestjs/typeorm": "^7.1.0",
    "@types/bcrypt": "^3.0.0",
    "@types/cookie-parser": "^1.4.2",
    "@types/joi": "^14.3.4",
    "@types/pluralize": "0.0.29",
    "bcrypt": "^5.0.0",
    "class-transformer": "^0.3.1",
    "class-validator": "^0.12.2",
    "cookie-parser": "^1.4.5",
    "joi": "^17.2.0",
    "mysql": "^2.18.1",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "pluralize": "^8.0.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^6.5.4",
    "typeorm": "^0.2.25"

What could be the reason of this error ?
How can I detect them ?
If someone has opinion,please let me know .
Thanks

seems that pluralize_1.default is undefined ... where is it defined?

I guess that is declared in const pluralize_1 = require("pluralize"); . thanks

Use --esModuleInterop: https://www.typescriptlang.org/tsconfig#esModuleInterop
