Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Cannot import decorators-legacy in V7

Open
#552 11 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
documentation

Research direction

Start with the v7 has-many documentation page and the decorators-legacy import shown there; compare it with the package entry points exposed by @sequelize/[email protected] using the provided TypeScript reproduction and tsconfig.json. Done means the documented example no longer produces the reported module-resolution error, with the relevant documentation or package behavior verified.

Written by the indexing model from the issue text.

Description

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Bug Description

The documentation explicitly indicates to use decorators to define all aspects related to a model.
From types, to relationships, and more.

However, I personally cannot get it to work, due to this issue in my VSCode editor

Cannot find module '@sequelize/core/decorators-legacy' or its corresponding type declarations.ts(2307)
Reproducible Example
  • I use TypeScript
  • Everything works fine without importing or trying to use decorators. I.e.:
import { Model, DataTypes, InferAttributes, InferCreationAttributes, CreationOptional } from '@sequelize/core'
import { RequestType } from '../types'
import { sequelize } from '../db'

class Request extends Model<InferAttributes<Request>, InferCreationAttributes<Request>> {
  declare id: CreationOptional<number>
  declare requestType: string
  declare requestData: object
  declare requester: string
  declare createdAt: CreationOptional<Date>
  declare updatedAt: CreationOptional<Date>
}

Request.init({
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  requestType: {
    type: DataTypes.ENUM(
      RequestType.EXPENV_AZURE,
      RequestType.EXPENV_GCP,
      RequestType.VM_AZURE,
      RequestType.VM_GCP,
      RequestType.RPA_AZURE,
      RequestType.RPA_GCP,
      RequestType.AZURE_RG
    ),
    allowNull: true
  },
  requestData: {
    type: DataTypes.JSON,
    allowNull: false
  },
  requester: {
    type: DataTypes.STRING,
    allowNull: false
  },
  createdAt: {
    type: DataTypes.DATE
  },
  updatedAt: {
    type: DataTypes.DATE
  }
}, { sequelize })
  • The sequelize directory inside node_modules seems to have all the requested data
image

However, and as per a standard example on this page, the usual flow to use decorators

import { Model, DataTypes, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute } from '@sequelize/core'
import { PrimaryKey, Attribute, AutoIncrement, NotNull, HasMany, BelongsTo } from '@sequelize/core/decorators-legacy'

has the second line, no matter what else I have in my file, always throw this error:
Cannot find module '@sequelize/core/decorators-legacy' or its corresponding type declarations.ts(2307)

What do you expect to happen?

Find the module and not throw that error

What is actually happening?
Environment
  • Sequelize version:
$ npm list @sequelize/core
[email protected] 
└── @sequelize/[email protected]
  • Node.js version:
$ node -v
v18.12.1
  • If TypeScript related: TypeScript version:
npm list typescript
[email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
  ├─┬ @typescript-eslint/[email protected]
  │ └─┬ [email protected]
  │   └── [email protected] deduped
  ├─┬ [email protected]
  │ └── [email protected] deduped
  └── [email protected] deduped
  • tsconfig.json
{
  "compilerOptions": {
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "dist",
    "rootDir": ".",
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "strictNullChecks": true,
    "target": "es6",
    "types": ["node"],
  },
}

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.

Dominant language
HTML
Stars
30
Forks
171
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sequelize/website

All issues in sequelize/website

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.