Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Cannot import decorators-legacy in V7

Aperta
#552 11 commenti 4 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
documentation

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
HTML
Stelle
30
Fork
171
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sequelize/website

Tutte le issue di sequelize/website

Issue simili

Altre issue su Documentation

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.