sequelize: Typescript 4.5.4 does not like sequelize-ESM imports in v6.12

My understanding of https://github.com/sequelize/sequelize/pull/13689, included in v6.12 is, that sequelize is not any more exported just in CommonJS, but can be used also as ESM-imports. Thus, the code in v6.11

import sequelize_ from 'sequelize'
const {DataTypes, Model, Op} = sequelize_ //this is CommonJS hack

can be changed in 6.12 to import {DataTypes, Model, Op} from 'sequelize'.

Typescript 4.5.4 fails on the above code with

$ node_modules/.bin/tsc
node_modules/sequelize/lib/operators.ts:524:1 - error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.

524 export = Op;
    ~~~~~~~~~~~~

Found 1 error.

My understanding is, that Typescript is only supposed to verify the types in sequelize by parsing the code in the node_modules/sequelize/types directory, and not loose time to verify each file in node_modules/sequelize/lib/. But types/index.d.ts contains import * as Op from "../lib/operators"; so my assumption is not correct. Likewise for node_modules/sequelize/types/lib/model.d.ts:import * as Op from '../../lib/operators';

Bug Report Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.

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

  • No, I don’t have the time and I wouldn’t even know how to start.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 21 (16 by maintainers)

Most upvoted comments

Hi @ephys I found the problem. I checked out the tip of the main branch and ran npm install. npm looks at package.json, namely esbuild@^0.14.1, and installs whatever latest version is after 0.14.1 which currently is 0.14.8. I recalled that yarn seems to be what you are using, so I ran yarn install. that one looks at yarn.lock which has version 0.14.1 locked in.

Version0.14.1 of esbuild does not show the problem, version 0.14.8 does. So, I think you might want to lock esbuild to version 0.14.1 in package.json until you remove the workaround in operators.js.

Now it works.

Can you give it a try and reopen if still an issue?

@WikiRik Yep! I’ll look into this 😃

I’m having this issue also since the 6.12 release

Changing export = Op; to export default Op; Then changing cjs imports from require('./operators') to require('./operators').default and esm imports from import * as Op to import Op seems to pass typescript tests, but I don’t know if there’s any other consequences and whether this sort of change conforms with your code style.