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

TypeScript import issue #780

Open
joergbaier opened this issue Oct 8, 2024 · 1 comment
Open

TypeScript import issue #780

joergbaier opened this issue Oct 8, 2024 · 1 comment
Labels

Comments

@joergbaier
Copy link

joergbaier commented Oct 8, 2024

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.

@joergbaier joergbaier added the bug label Oct 8, 2024
@sebastianluczak
Copy link

I'm also affected by this issue. Is there any plan to resolve it in near future?

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

No branches or pull requests

2 participants