patternfly-react icon indicating copy to clipboard operation
patternfly-react copied to clipboard

Bug - Package Publishing - Published Libraries should follow NPM dual module package standards

Open jamestalton opened this issue 11 months ago • 2 comments

PatternFly libraries should follow NPM standards for publishing dual module (CommonJS/ESModule) packages.

PatternFly packages have

  "main": "dist/js/index.js",
  "module": "dist/esm/index.js",
  "types": "dist/esm/index.d.ts",

This is a really early format when es modules were being initially developed and not supported by modern tooling.

NPM documentation links to this as the right way to handle dual module packages.

{
  "type": "module",
  "exports": {
    "import": "./index.mjs",
    "require": "./index.cjs"
  }
}

Modern tooling like vite builds libraries with a combination of both for compatibility.

{
  "name": "my-lib",
  "type": "module",
  "main": "./dist/my-lib.umd.cjs",
  "types": "./dist/my-lib.d.ts",
  "module": "./dist/my-lib.js",
  "exports": {
    ".": {
      "import": "./dist/my-lib.js",
      "require": "./dist/my-lib.umd.cjs"
    }
  }
}

This is currently blocking us from using vitest to test because it gets really confused. It tries to import the code as ESM but then is unhappy that the package is not marked as type "module". If we manually add type 'module', it then runs into some code that uses a 'require', which is not valid in the scope of a module.

PatternFly packages should support both ESM and CommonJS using NPM standards for better compatibility.

This affects all PF packages not just react-core.

jamestalton avatar Mar 18 '25 19:03 jamestalton

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar May 23 '25 11:05 github-actions[bot]

@kmcfaul Can we look at getting this into a sprint to get this out. It's currently blocking teams from using vite testing and playwright. We should look at getting this addressed for an upcoming release. May have to do a patch release since we can't wait for Q3 release for this.

dlabaj avatar Jun 12 '25 13:06 dlabaj

Still really interested in this as it is blocking us from using vitest.

jamestalton avatar Jun 24 '25 15:06 jamestalton

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar Aug 27 '25 11:08 github-actions[bot]