Skip to content

fetches default export doesn't work for ESM #19

@MiaInturi

Description

@MiaInturi

Description

Because fetches package.json doesn't have type property it means that all d.ts files are treated as commonjs.

So when we import package typescript treats it like ESM is trying to import CJS.

// index.mts

import fetches from "@siberiacancode/fetches";

...

This behavior leads to situation where we have types not like in full ESM environment but for enviroment where node js tries to interop CJS and ESM. From official doc: To support this, when importing CommonJS from an ECMAScript module, a namespace wrapper for the CommonJS module is constructed, which always provides a default export key pointing to the CommonJS module.exports value.

So even if in reality default import works well typescript force us to use .default property:
Image

Current behavior

Typescript treats import fetches package from ESM as interop of CJS and ESM.

Expected behavior

Because fetches package has different builds for CJS and ESM typescript has to treat types accordingly.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions