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

[Bug]: ESM import of @fullhuman/postcss-purgecss has incorrect TypeScript type #1263

Open
1 task done
mdmower opened this issue Jun 30, 2024 · 2 comments
Open
1 task done
Assignees
Labels

Comments

@mdmower
Copy link

mdmower commented Jun 30, 2024

Describe the bug

When I set my project to ESM ("type": "module" in package.json), the import of @fullhuman/postcss-purgecss in my build script has the wrong type. I have to coerce the type with (purgecss as unknown as typeof purgecss.default)({...}) for the type check to pass.

To Reproduce

I've created a minimal example at https://github.com/mdmower/purgecss-export/ to demonstrate this issue. After cloning the project and running npm install, you can run npm run check-types to see the type error (it's also visible in VSCode, see file build/build.ts).

Expected Behavior

ESM import type of @fullhuman/postcss-purgecss should be a function.

Environment

Debian 12
Node.js 20.15.0
npm 10.8.1

    "@fullhuman/postcss-purgecss": "^6.0.0",
    "@types/node": "^20.14.9",
    "css-loader": "^7.1.2",
    "postcss-loader": "^8.1.1",
    "style-loader": "^4.0.0",
    "ts-loader": "^9.5.1",
    "tsx": "^4.16.0",
    "typescript": "^5.5.2",
    "webpack": "^5.92.1"

Add any other context about the problem here

Potentially useful resources:

Code of Conduct

  • I agree to follow this project's Code of Conduct
@mdmower mdmower added the bug label Jun 30, 2024
@Ffloriel Ffloriel self-assigned this Sep 28, 2024
@Ffloriel
Copy link
Member

Thanks for looking into it.
At the moment, the "fix" would be to use the default export with:

      purgecss.default({
        content: ["src/index.ts"],
      }),

I will add a named export for purgeCSSPlugin, so that in the future it will be imported with

import { purgeCSSPlugin } from "@fullhuman/postcss-purgecss"

Ffloriel added a commit that referenced this issue Sep 29, 2024
@brybrant
Copy link

When will next package version be published? I need this

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

3 participants