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

terser plugin doesn't pass check by typescript (TS1479) #1795

Open
eXory2024 opened this issue Oct 19, 2024 · 2 comments
Open

terser plugin doesn't pass check by typescript (TS1479) #1795

eXory2024 opened this issue Oct 19, 2024 · 2 comments

Comments

@eXory2024
Copy link

Expected Behavior

No error should be emitted by tsc.

Actual Behavior

The following error is emitted by tsc:

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("terser")' call instead.

2 import type { MinifyOptions } from 'terser';
                                     ~~~~~~~~


Found 1 error in node_modules/@rollup/plugin-terser/types/index.d.ts:2

Additional Information

The rollup config is intentionally not populated as it is not relevant to the bug / behaviour.

@notaphplover
Copy link

Yeah, https://arethetypeswrong.github.io/?p=%40rollup%2Fplugin-terser%400.4.4. Are you open to accept PR?

@eXory2024
Copy link
Author

I would if I knew what had to be done exactly.

It looks to me the issue arises from having only one d.ts file from both the cjs and es export.

The website you posted links to a document that suggests defining a separate d.ts file for the cjs and es export like so:

{
  "name": "pkg",
  "exports": {
    ".": {
      "import": {
        "types": "./index.d.mts",
        "default": "./index.mjs"
      },
      "require": {
        "types": "./index.d.ts",
        "default": "./index.js"
      }
    }
  }
}

However this would mean duplicating the index.d.ts file since (from what I can tell) it is handwritten and not automatically generated.

I really don't know much about how TypeScript handles CommonJS to be able to formulate a solution in my own time.

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

2 participants