Nest: Problem with @nestjs/sequelize

Created on 26 Jun 2020  路  4Comments  路  Source: nestjs/nest

Bug Report

Current behavior


I am following this publication to integrate sequelize https://docs.nestjs.com/techniques/database#sequelize-integration but when i do import { SequelizeModule } from '@nestjs/sequelize'; I run npm run start and throw this error.

node_modules/sequelize-typescript/dist/associations/belongs-to-many/belongs-to-many-association.d.ts:12:5 - error TS2416: Property 'getSequelizeOptions' in type 'BelongsToManyAssociation' is not assignable to the same property in base type 'BaseAssociation'.
  Type '(model: typeof import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize/types/lib/model").Model, sequelize: import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize-typescript/dist/sequelize/sequelize/sequelize").Sequelize) => import("/home/rmedina/ml/shield-refactor/example-n...' is not assignable to type '(model: typeof import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize-typescript/dist/model/model/model").Model, sequelize: import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize-typescript/dist/sequelize/sequelize/sequelize").Sequelize) => import("/home/rmedina/ml/shield-...'.
    Types of parameters 'model' and 'model' are incompatible.
      Type 'typeof import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize-typescript/dist/model/model/model").Model' is not assignable to type 'typeof import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize/types/lib/model").Model'.
        Types of property 'init' are incompatible.
          Type '(attributes: ModelAttributes<Model<any, any>, any>, options: InitOptions<Model<any, any>>) => void' is not assignable to type '<M extends Model<any, any>>(this: ModelStatic<M>, attributes: ModelAttributes<M, M["_creationAttributes"]>, options: InitOptions<M>) => Model<...>'.

12     getSequelizeOptions(model: typeof Model, sequelize: Sequelize): UnionAssociationOptions;
       ~~~~~~~~~~~~~~~~~~~
node_modules/sequelize-typescript/dist/associations/has/has-association.d.ts:11:5 - error TS2416: Property 'getSequelizeOptions' in type 'HasAssociation' is not assignable to the same property in base type 'BaseAssociation'.
  Type '(model: typeof Model) => UnionAssociationOptions' is not assignable to type '(model: typeof Model, sequelize: Sequelize) => UnionAssociationOptions'.
    Types of parameters 'model' and 'model' are incompatible.
      Type 'typeof import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize-typescript/dist/model/model/model").Model' is not assignable to type 'typeof import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize/types/lib/model").Model'.

11     getSequelizeOptions(model: typeof Model): UnionAssociationOptions;
       ~~~~~~~~~~~~~~~~~~~
node_modules/sequelize-typescript/dist/model/model/model.d.ts:1:89 - error TS2305: Module '"../../../../sequelize/types"' has no exported member 'Promise'.

1 import { InitOptions, Model as OriginModel, ModelAttributes, FindOptions, BuildOptions, Promise } from 'sequelize';
                                                                                          ~~~~~~~
node_modules/sequelize-typescript/dist/model/model/model.d.ts:9:31 - error TS2417: Class static side 'typeof import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize-typescript/dist/model/model/model").Model' incorrectly extends base class static side 'typeof import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize/types/lib/model").Model'.
  The types returned by 'init(...)' are incompatible between these types.
    Type 'void' is not assignable to type 'Model<any, any>'.

9 export declare abstract class Model<T = any, T2 = any> extends OriginModel<T, T2> {
                                ~~~~~
node_modules/sequelize-typescript/dist/sequelize/sequelize/sequelize.d.ts:12:5 - error TS2416: Property 'model' in type 'Sequelize' is not assignable to the same property in base type 'Sequelize'.
  Type '(model: string | typeof Model) => ModelCtor<Model<any, any>>' is not assignable to type '(modelName: string) => ModelCtor<Model<any, any>>'.
    Type 'import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize-typescript/dist/model/model/model").ModelCtor<import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize-typescript/dist/model/model/model").Model<any, any>>' is not assignable to type 'import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize/types/lib/model").ModelCtor<import("/home/rmedina/ml/shield-refactor/example-nest/node_modules/sequelize/types/lib/model").Model<any, any>>'.
      Type 'ModelCtor<Model<any, any>>' is not assignable to type 'typeof Model'.
        The types returned by 'init(...)' are incompatible between these types.
          Type 'void' is not assignable to type 'Model<any, any>'.

12     model(model: string | typeof Model): ModelCtor;

Input Code


This is empty project created with nest clic.

app.module

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SequelizeModule } from '@nestjs/sequelize';

@Module({
  imports: [
    // SequelizeModule.forRoot({
    //   dialect: 'mysql',
    //   host: 'localhost',
    //   port: 3306,
    //   username: 'root',
    //   password: 'root',
    //   database: 'test',
    //   models: [],
    // }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Expected behavior


add Sequelize successfully

Environment


Nest version: 7.0.0


For Tooling issues:
- Node version: 10.13.0  
- Platform: Linux 

Others:

package

package.json

{
  "name": "example-nest",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "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": {
    "@nestjs/common": "^7.0.0",
    "@nestjs/core": "^7.0.0",
    "@nestjs/platform-express": "^7.0.0",
    "@nestjs/sequelize": "^0.1.0",
    "mysql2": "^2.1.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^6.5.4",
    "sequelize": "^6.2.0",
    "sequelize-typescript": "^1.1.0"
  },
  "devDependencies": {
    "@nestjs/cli": "^7.0.0",
    "@nestjs/schematics": "^7.0.0",
    "@nestjs/testing": "^7.0.0",
    "@types/express": "^4.17.3",
    "@types/jest": "25.2.3",
    "@types/node": "^13.9.1",
    "@types/sequelize": "^4.28.9",
    "@types/supertest": "^2.0.8",
    "@typescript-eslint/eslint-plugin": "3.0.2",
    "@typescript-eslint/parser": "3.0.2",
    "eslint": "7.1.0",
    "eslint-config-prettier": "^6.10.0",
    "eslint-plugin-import": "^2.20.1",
    "jest": "26.0.1",
    "prettier": "^1.19.1",
    "supertest": "^4.0.2",
    "ts-jest": "26.1.0",
    "ts-loader": "^6.2.1",
    "ts-node": "^8.6.2",
    "tsconfig-paths": "^3.9.0",
    "typescript": "^3.7.4"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".spec.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}


needs triage

Most helpful comment

I have no problem using the following version

npm i sequelize-typescript@next
"sequelize-typescript": "^2.0.0-beta.0"



md5-18f6227b3955c02a34918668997d06d2



"sequelize": "^6.1.1"

sequelize 6 version, only 6.1.1 tested

All 4 comments

sequelize-typescript doesn't seem to be compatible with sequelize v6 just yet. Let's track this here https://github.com/RobinBuschmann/sequelize-typescript/issues/804 For now, you can revert your sequelize version to v5

ok Thanks @kamilmysliwiec

I have no problem using the following version

npm i sequelize-typescript@next
"sequelize-typescript": "^2.0.0-beta.0"



md5-18f6227b3955c02a34918668997d06d2



"sequelize": "^6.1.1"

sequelize 6 version, only 6.1.1 tested

Looks like they are already working on this issue
https://github.com/RobinBuschmann/sequelize-typescript/issues/804

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mishelashala picture mishelashala  路  3Comments

janckerchen picture janckerchen  路  3Comments

menme95 picture menme95  路  3Comments

KamGor picture KamGor  路  3Comments

thohoh picture thohoh  路  3Comments