How to fix Angular 18 error: A namespace-style import cannot be called or constructed ...


After upgrading your Angular application to Angular 18, you see build error such as:

✘ [ERROR] TS2349: This expression is not callable.
  Type 'typeof import("/home/uli/myproject/node_modules/dayjs/index.d.ts")' has no call signatures. [plugin angular-compiler]

      37 │     const d2 = dayjs(d);
         ╵                ~~~~~

  Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.

      3 │ import * as dayjs from 'dayjs'


Typescript 5.4 does not support the import * as X from 'X any more.

Therefore, you need to change

import * as dayjs from 'dayjs'


import dayjs from 'dayjs'