Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
grabbou opened this issue Jul 21, 2024 · 4 comments

Comments

@grabbou
Copy link

grabbou commented Jul 21, 2024

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.

@antongolub
Copy link
Collaborator

antongolub commented Jul 21, 2024

@grabbou,

Could you provide a full code example for debug?

  • zx version
  • platform
  • reproducible setup
    • index.ts
    • package.json
    • tsconfig.json
    • tsc build params

@grabbou
Copy link
Author

grabbou commented Jul 22, 2024

@grabbou
Copy link
Author

grabbou commented Jul 28, 2024

I would be happy to look into this and provide a proposed solution, once approved, submit a follow up PR. @antongolub et al, please let me know if you would consider a PR that fixes this.

antonmedv pushed a commit that referenced this issue Aug 27, 2024
* chore: up dev deps

* fix(types): add missing minimist typings to dts bundle

relates #871

* chore: linting
@antongolub
Copy link
Collaborator

@grabbou,

This should be fixed in 8.1.5. Could you check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants