Skip to content

2.4.0: CommonJS build no longer exports the class as module.exports — breaks default import and every TypeScript consumer #133

Description

@DenisFrezzato

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

  1. 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
  1. 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
  1. 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'.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions