voxpelli / node-connect-pg-simple

A simple, minimal PostgreSQL session store for Express
https://www.npmjs.com/package/connect-pg-simple
MIT License
237 stars 74 forks source link

TypeError: (0 , connect_pg_simple_1.default) is not a function #304

Open MuttakinHasib opened 11 months ago

MuttakinHasib commented 11 months ago

Assalamualaikom, @voxpelli

It's throwing TypeError: (0 , connect_pg_simple_1.default) is not a function

Nestjs: v10 Nodejs: v20.10.0 Postgres: v16

main.ts

import '@colors/colors';
import { Logger, ValidationPipe } from '@nestjs/common';
import { ConfigurationService, NestHttpExceptionFilter } from '@app/common';
import { NestFactory } from '@nestjs/core';
import * as passport from 'passport';
import * as session from 'express-session';
import PostgresStore from 'connect-pg-simple';
import helmet from 'helmet';
import { NestExpressApplication } from '@nestjs/platform-express';
import { shouldSendSameSiteNone } from 'should-send-same-site-none';

import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

const pgSession = PostgresStore(session);

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  const configurationService =
    app.get<ConfigurationService>(ConfigurationService);

  app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
  app.useGlobalFilters(new NestHttpExceptionFilter());
  app.enableCors({
    credentials: true,
    origin: [configurationService.WEB_URL],
  });

  app.use(helmet());

  // Swagger Setup
  const config = new DocumentBuilder()
    .setTitle(
      `${configurationService.APP_NAME} - An Islamic E-Commerce Web Application`,
    )
    .setDescription(`${configurationService.APP_NAME} API description`)
    .setVersion('1.0')
    .addServer(configurationService.API_URL)
    .build();

  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('docs', app, document);

  app.use(shouldSendSameSiteNone);

  app.use(
    session({
      secret: configurationService.SESSION_SECRET_KEY,
      resave: false,
      saveUninitialized: false,
      cookie: {
        maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days
        httpOnly: true,
        sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
        secure: process.env.NODE_ENV === 'production',
      },
      store: new pgSession({
        conString: process.env.POSTGRES_DB_URL,
        createTableIfMissing: true,
      }),
    }),
  );

  app.set('trust proxy', 1);

  app.use(passport.initialize());
  app.use(passport.session());

  const port = process.env.PORT || 3333;
  await app.listen(port);

  Logger.log(
    `šŸš€ Alhamdulillah! Application is running on: ${await app.getUrl()}`.bgCyan
      .black,
  );
}

bootstrap();

package.json

{
  "name": "api",
  "version": "0.0.1",
  "description": "",
  "author": "Muttakin Islam Hasib",
  "license": "ISC",
  "private": true,
  "scripts": {
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"libs/**/*.ts\"",
    "start": "nest start",
    "dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@colors/colors": "^1.6.0",
    "@nestjs-modules/mailer": "^1.9.1",
    "@nestjs/common": "^10.0.0",
    "@nestjs/config": "^3.1.1",
    "@nestjs/core": "^10.0.0",
    "@nestjs/jwt": "^10.2.0",
    "@nestjs/passport": "^10.0.3",
    "@nestjs/platform-express": "^10.0.0",
    "@nestjs/swagger": "^7.1.16",
    "@nestjs/terminus": "^10.2.0",
    "@nestjs/typeorm": "^10.0.1",
    "bcryptjs": "^2.4.3",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.0",
    "connect-pg-simple": "^9.0.1",
    "express-session": "^1.17.3",
    "handlebars": "^4.7.8",
    "helmet": "^7.1.0",
    "joi": "^17.11.0",
    "lodash": "^4.17.21",
    "moment": "^2.29.4",
    "nanoid": "3",
    "nodemailer": "^6.9.7",
    "passport": "^0.7.0",
    "passport-local": "^1.0.0",
    "pg": "^8.11.3",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.8.1",
    "should-send-same-site-none": "^2.0.5",
    "slugify": "^1.6.6",
    "typeorm": "^0.3.17"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.0.0",
    "@nestjs/schematics": "^10.0.0",
    "@nestjs/testing": "^10.0.0",
    "@types/bcrypt": "^5.0.2",
    "@types/bcryptjs": "^2.4.6",
    "@types/connect-pg-simple": "^7.0.3",
    "@types/express": "^4.17.17",
    "@types/express-session": "^1.17.10",
    "@types/jest": "^29.5.2",
    "@types/lodash": "^4",
    "@types/moment": "^2.13.0",
    "@types/node": "^20.3.1",
    "@types/passport-local": "^1.0.38",
    "@types/supertest": "^2.0.12",
    "@typescript-eslint/eslint-plugin": "^6.0.0",
    "@typescript-eslint/parser": "^6.0.0",
    "eslint": "^8.42.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.0",
    "jest": "^29.5.0",
    "prettier": "^3.0.0",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.3",
    "ts-jest": "^29.1.0",
    "ts-loader": "^9.4.3",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.1.3"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": ".",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "./coverage",
    "testEnvironment": "node",
    "roots": [
      "<rootDir>/src/",
      "<rootDir>/libs/"
    ],
    "moduleNameMapper": {
      "^@app/common(|/.*)$": "<rootDir>/libs/common/src/$1",
      "^@app/mail(|/.*)$": "<rootDir>/libs/mail/src/$1",
      "^@app/types(|/.*)$": "<rootDir>/libs/types/src/$1"
    }
  }
}
voxpelli commented 11 months ago

I think this is due to how your TypeScript is set up - what it compiles to and how it handles imports when it does that compilation

What's your tsconfig?

MuttakinHasib commented 11 months ago

tsconfig.json


{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2021",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "paths": {
      "@app/common": [
        "libs/common/src"
      ],
      "@app/common/*": [
        "libs/common/src/*"
      ],
      "@app/mail": [
        "libs/mail/src"
      ],
      "@app/mail/*": [
        "libs/mail/src/*"
      ],
      "@app/types": [
        "libs/types/src"
      ],
      "@app/types/*": [
        "libs/types/src/*"
      ]
    }
  }
}