Skip to content

Default import doesn't return a component after codebase was migrated to Typescript #434

@tricoder42

Description

@tricoder42

🐛 Bug report

Current Behavior

VisuallyHidden component causes error, because default import returns an object instead of a component:

import VisuallyHidden from '@reach/visually-hidden'

console.log(VisuallyHidden)
// {
//   default: {
//     ... component here
//   }
// }

Expected behavior

Default import should return a component:

import VisuallyHidden from '@reach/visually-hidden'

console.log(VisuallyHidden)
// {
//   ... component here
// }

Reproducible example

Fresh Next.js install with only Typescsript and @reach/visually-hidden dependencies.
GitHub Repository

Suggested solution(s)

When I edit source of visually-hidden.development.js manually and change last line exports.default = to module.exports = , then it works. It's either build issue or my tsconfig issue.

Edit: It seems that build files are missing Object.defineProperty(exports, '__esModule', { value: true }); line. Add this line to source solves the problem as well. I've checked tsdx, and it seems to be configured correctly (i.e. respecting esModuleInterop settings from tsconfig.json)

Additional context

  • It only affects components with default exports only (i.e. VisuallyHidden). Other components works fine (e.g. Menu).
  • I tried update tsconfig, but I'm using the official one from Next.js without any modification.
  • The bug appeard after 0.7.0, when codebase was migrated to Typescript.
  • I tried to interop default export manually and noticed, this only happens on server (i.e. running in Node.js).

Your environment

Software Name(s) Version
Reach Package @reach/visually-hidden 0.7.3
Typescript 3.7.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedBug reports without a repro, not yet confirmed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions