Summary
In 2.4.0 the CommonJS bundle changed shape: module.exports used to be the CodiceFiscale class, and is now a plain object { CodiceFiscale }. The bundled type declarations were not changed to match — types/codice-fiscale.d.ts still declares export default CodiceFiscale and does not export the class under a name. The result is that there is no combination of import style that both typechecks and works at runtime, and plain CommonJS require() usage is broken too. This landed in a minor release.
Reproduction
- Plain CommonJS — worked in 2.3.23, throws in 2.4.0:
const CodiceFiscale = require('codice-fiscale-js')
new CodiceFiscale('CLSSNT66H06E374J')
// TypeError: CodiceFiscale is not a constructor
- TypeScript with esModuleInterop — compiles clean (the shipped types promise a default
export), fails at runtime:
import CodiceFiscale from 'codice-fiscale-js'
new CodiceFiscale('CLSSNT66H06E374J')
// TypeError: codice_fiscale_js_1.default is not a constructor
- Named import — works at runtime, but fails typecheck, because the class is not exported by
name from the .d.ts:
import { CodiceFiscale } from 'codice-fiscale-js'
// error TS2614: Module '"codice-fiscale-js"' has no exported member 'CodiceFiscale'.
Summary
In 2.4.0 the CommonJS bundle changed shape: module.exports used to be the CodiceFiscale class, and is now a plain object { CodiceFiscale }. The bundled type declarations were not changed to match — types/codice-fiscale.d.ts still declares export default CodiceFiscale and does not export the class under a name. The result is that there is no combination of import style that both typechecks and works at runtime, and plain CommonJS require() usage is broken too. This landed in a minor release.
Reproduction
export), fails at runtime:
name from the .d.ts: