Skip to content

yarn jest TypeError: xxx.default is not a constructor -- default export not output as expected #83

@liyuanqiu

Description

@liyuanqiu

Current Behavior

tsdx yarn test will report error:

TypeError: xxx.default is not a constructor

when import a class created by tsdx and try to instance it.

reproduction:

  1. create a lib using tsdx
tsdx create mylib-a
  1. modify index.ts to a class
// mylib-a/src/index.ts
export default class MyLibA {}
  1. build
yarn build
  1. create another lib using tsdx called mylib-b
  2. move mylib-a to mylib-b/src/
  3. import mylib-a in mylib-b/test/blah.test.ts
import MyLibA from '../src/mylib-a';
// this line is error when `yarn test`
// TypeError: xxx.default is not a constructor
const instance = new MyLibA();
  1. yarn test

If I don't use default to export class:

export class MyLibA {}

And import like this:

import { MyLibA } from ...;

Everything will be ok, but it is just a workaround.

Expected behavior

Suggested solution(s)

Additional context

Your environment

Software Version(s)
TSDX ^0.5.6
TypeScript ^3.4.5
Browser -
npm/Yarn yarn@1.13.0
Operating System macOS Mojave version 10.14.4 (18E226)

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugSomething isn't workingkind: featureNew feature or requestsolution: duplicateThis issue or pull request already exists

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions