Skip to content

Importing this package into CJS project triggers false-positive TypeScript error #871

@grabbou

Description

@grabbou

Expected Behavior

The following should work without any errors:

import { $ } from 'zx'

Actual Behavior

Triggers the following error:

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("zx")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to 'package.json'.ts(1479)

However, the project works just fine. This is because main in package.json is set to a CJS entry-point (thank you!)

The only alternative I am aware of is setting {type: module} inside esm build directory. It would be great if zx could be used in both ESM and CJS projects without warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions