Skip to content

Jest fails on standard import syntax #869

@clemenger

Description

@clemenger

When importing Tooltip, Jest throws the following error unless you specifically import the cjs version.
react-tooltip v5.2.0
To reproduce, in a project running Node 18, React 18, and Jest 29, import tooltip:

import { Tooltip as ReactTooltip, ITooltip } from 'react-tooltip';

Project runs fine, but jest tests fail.

When running jest tests I see the following error:

Jest encountered an unexpected token
    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
...node_modules/react-tooltip/dist/react-tooltip.esm.min.js:1

So, it's possible it's just my jest configuration that is unable to support this syntax, but the tests run fine with standard imports from other react ui packages.

Current solution: directly import from the dist directory's .cjs version.

import { Tooltip as ReactTooltip, ITooltip } from '../../node_modules/react-tooltip/dist/react-tooltip.cjs';

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions