sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

using ESM - model methods are broken

Open dcsan opened this issue 3 years ago • 0 comments

Issue

when trying to use ES Modules, many of the default Model methods are missing from my classes.

image

interestingly the asset.save method doesn't throw an error?

where Asset is just a model:

@Table
export class Asset extends Model {

Versions

  • sequelize:
  • sequelize-typescript:
  • typescript:
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]

└── [email protected]

├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]

Issue type

  • [X] bug report
  • [ ] feature request

Actual behavior

cannot call basic sequelize methods on any model such as MyModel.truncate() or MyModel.create()

where MyModel is a subclass of Model

Expected behavior

should be able to create!

Steps to reproduce

have to use ESM modules

Related code

This is all configuration bullshit. I'm putting my tsconfig and package.json below.


{
    "compilerOptions": {
        "rootDir": "src",
        "outDir": "./build",
        "lib": [
            "ESNext"
        ],
        "module": "NodeNext",
        "moduleResolution": "NodeNext",
        "target": "es2022",
        "esModuleInterop": true,
        "types": [
            "node"
        ],
        "sourceMap": true,
        "strict": true,
        "strictPropertyInitialization": false,
        "baseUrl": "./src",
        "paths": {
            "@sharedTypes/*": [
                "../../client/src/types/shared/*"
            ]
        },
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true,
        "allowJs": false
    },
    "include": [
        "src/**/*",
        "../../client/src/types/**/*"
    ],
    "exclude": [
        "node_modules"
    ],
    "typedocOptions": {
        "entryPoints": [
            "src/server.ts"
        ],
        "out": "docs/build"
    },
    "ts-node": {
        "esm": true,
        "experimentalSpecifierResolution": "node",
        "require": [
            "tsconfig-paths/register"
        ]
    }
}

and top of package.json


{
    "name": "plugbot-server",
    "version": "0.0.3",
    "description": "A framework for extensible crypto related discord bots with plugins",
    "main": "index.js",
    "type": "module",

...

    "nodemonConfig": {
        "ignore": [
            "*.json"
        ],
        "events": {
            "start": "clear || cls"
        }
    }


dcsan avatar Jul 24 '22 06:07 dcsan