배꼽파지 않도록 잘 개발해요

This expression is not constructable. Type 'typeof UAParser' has no construct signatures.ts(2351) 본문

BackEnd/TypeScript

This expression is not constructable. Type 'typeof UAParser' has no construct signatures.ts(2351)

꼽파 2025. 7. 22. 23:34

https://docs.uaparser.dev/intro/quick-start/using-es-modules-typescript.html

 

만약 named export를 default export처럼 import 하면 다음과 같은 일이 발생한다.

This expression is not constructable. Type 'typeof UAParser' has no construct signatures.ts(2351)
(alias) namespace UAParser import UAParser
  • "This expression is not constructable": new UAParser()로 인스턴스를 만들 수 없다
  • "Type 'typeof UAParser' has no construct signatures": UAParser 타입에 생성자가 정의되어 있지 않다
  • "(alias) namespace UAParser": TypeScript가 UAParser를 네임스페이스로 인식하고 있다

Named export

import { UAParser } from 'ua-parser-js';

 

Default export

import UAParser from 'ua-parser-js';

 

결론

  • ua-parser-js 라이브러리는 다음과 같이 export 되어 있음.
export class UAParser { ... } // named export
  • import { UAParser }: 실제 클래스를 가져옴 → new UAParser() 가능 (O)
  • import UAParser: 전체 모듈을 가져옴 → 생성자가 아닌 네임스페이스로 인식 (X)
728x90