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)
Hi @ephys I found the problem. I checked out the tip of the main branch and ran
npm install.npmlooks at package.json, namelyesbuild@^0.14.1, and installs whatever latest version is after0.14.1which currently is0.14.8. I recalled thatyarnseems to be what you are using, so I ranyarn install. that one looks atyarn.lockwhich has version0.14.1locked in.Version
0.14.1of esbuild does not show the problem, version0.14.8does. So, I think you might want to lock esbuild to version0.14.1inpackage.jsonuntil you remove the workaround inoperators.js.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;toexport default Op;Then changing cjs imports fromrequire('./operators')torequire('./operators').defaultand esm imports fromimport * as Optoimport Opseems 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.