Problem with @nestjs/sequelize
See original GitHub issueBug 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"
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Problem connecting tables in Sequelize-Typescript NestJS
Problem : In my user.service.ts when I run this function const user = await this.userRepository.findOne({ where: { email }, include: { all: ...
Read more >SQL (Sequelize) | NestJS - A progressive Node.js framework
The first step we need to do is create a Sequelize instance with an options object passed into the constructor. Also, we need...
Read more >@nestjs/sequelize - npm
Nest - modern, fast, powerful node.js web framework (@sequelize). Latest version: 9.0.0, last published: 6 months ago.
Read more >Problem connecting tables in Sequelize-Typescript NestJS ...
[Solved]-Problem connecting tables in Sequelize-Typescript NestJS-sequelize.js ... That was my mistake. When you editing columns, you manually need to delete some ...
Read more >Comparing 4 popular NestJS ORMs - LogRocket Blog
ORMs have their limitations, such as performance issues with complex queries, ... To migrate an existing application to Sequelize in NestJS, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have no problem using the following version
sequelize 6 version, only 6.1.1 tested
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