Skip to content

TypeScript import issue #780

Description

@joergbaier

Description of the bug

fuse.js v7.0.0

import

import Fuse from "fuse.js";

tsconfig.json (https://github.com/tsconfig/bases/blob/main/bases/node20.json)

"module": "node16",
"moduleResolution": "node16",

package.json

"type": "commonjs",
"engines": {
  "node": "20.x"
},

typescript error

error TS1479: 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("fuse.js")' call instead. To convert this file to an ECMAScript module, change its file extension to '.mts' or create a local package.json file with { "type": "module" }.


Based on comments in this thread, this package incorrectly exports typings.
microsoft/TypeScript#53045 (comment)

The error was resolved when I copied fuse.d.ts to fuse.d.cts and manually edited node_modules/fuse.js/package.json

"exports": {
  ".": {
    "import": {
      "default":"./dist/fuse.mjs",
      "types": "./dist/fuse.d.ts"
    },
    "require": {
      "default":"./dist/fuse.cjs",
      "types": "./dist/fuse.d.cts"
    }
  }
}

Seems like fuse.js needs to expose d.cts and d.ts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions