While testing sequelize v7 (alpha) I came across several errors while using simple examples straight from their documentation. For example, straight from the documentation
import { Sequelize, DataTypes, Model, InferAttributes, InferCreationAttributes, CreationOptional } from '@sequelize/core';
import { Attribute, PrimaryKey, AutoIncrement, NotNull } from '@sequelize/core/decorators-legacy';
const sequelize = new Sequelize('sqlite::memory:');
export class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
@Attribute(DataTypes.INTEGER)
@PrimaryKey
@AutoIncrement
declare id: CreationOptional<number>;
@Attribute(DataTypes.STRING)
@NotNull
declare firstName: string;
@Attribute(DataTypes.STRING)
declare lastName: string | null;
}
Results in import error Cannot find module '@sequelize/core/decorators-legacy' or its corresponding type declarations.
Also, Decorators are not valid here. where we declare the @Attribute decorators error as well.
Following along with their documentation is proving to be difficult. Has anyone managed to implement sequelize v7 alpha? What am I doing wrong?
To resolve Cannot find module '@sequelize/core/decorators-legacy' or its corresponding type declarations. You must set the module and moduleResolution options to NodeNext.
To resolve Decorators are not valid here. You must set the experimentalDecorators option to true.
See an example
tsconfig.json
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"experimentalDecorators": true
...
}
According this thread Cannot import decorators-legacy in V7 you need change moduleResolution property in your tsconfig.json to node16 or nodenext value.
In my case I have a tsconfig.json and a tsconfig.serve.json I change both.
Note that after update moduleResolution you also need update de module property to the same value
See an example
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With