SreedharAvvari opened a new issue, #2397:
URL: https://github.com/apache/incubator-kie-issues/issues/2397

   ### Describe the bug
   
   `@kie-tools/xml-parser-ts` resolves to `dist/node/index.js` in Node 
(`package.json` `main`). That entry calls `require("jsdom")` at module load, 
but `jsdom` is not declared in `dependencies`, `peerDependencies` or 
`optionalDependencies`. Any Node consumer of `@kie-tools/dmn-marshaller` (which 
depends on `@kie-tools/xml-parser-ts`) therefore fails at bundle time, or at 
runtime, unless it installs `jsdom` itself.
   
   The `browser` build (`dist/index.js`) is environment-agnostic: its only DOM 
touchpoint is `domParser.getDomDocument`, which calls the global `DOMParser` 
and is already an overridable hook (the Node entry itself overrides it). So the 
parser core can run in Node with any DOM implementation, but the package's own 
entry-point wiring prevents it.
   
   ### Steps to reproduce
   
   ```sh
   mkdir repro && cd repro && npm init -y
   npm i @kie-tools/[email protected] [email protected]
   printf 'import { getMarshaller } from 
"@kie-tools/dmn-marshaller";\nconsole.log(typeof getMarshaller);\n' > entry.mjs
   npx esbuild entry.mjs --bundle --platform=node --outfile=out.cjs
   ```
   
   Output:
   
   ```
   ✘ [ERROR] Could not resolve "jsdom"
   
       node_modules/@kie-tools/xml-parser-ts/dist/node/index.js:20:20:
         20 │ var jsdom = require("jsdom");
   ```
   
   `jsdom` is not present in `node_modules` after the install above, confirming 
it is not declared.
   
   Installing `jsdom` manually makes the bundle build, but pulls jsdom (and its 
optional native `canvas` binding when present) into what should be a pure-JS 
bundle, and jsdom's `require.resolve("./xhr-sync-worker.js")` breaks in a 
single-file bundle at runtime.
   
   ### Expected behavior
   
   One of:
   
   1. Declare `jsdom` as an optional peer dependency and load it lazily, only 
when no global `DOMParser` is available; or
   2. Make the environment-agnostic build the default entry (`main` / `exports` 
default) and move the jsdom wiring to an explicit subpath such as 
`@kie-tools/xml-parser-ts/node`, so Node consumers can supply their own DOM 
implementation through `domParser.getDomDocument` (for example `@xmldom/xmldom` 
or `linkedom`).
   
   Either way, a Node consumer that never asks for jsdom should not have jsdom 
on its dependency path.
   
   ### Current workaround
   
   At the bundler level, resolve the bare `@kie-tools/xml-parser-ts` specifier 
to `dist/index.js`, provide a `DOMParser`, and set `domParser.getDomDocument` 
to use it.
   
   ### Environment
   
   - `@kie-tools/xml-parser-ts` 10.2.0, `@kie-tools/dmn-marshaller` 10.2.0
   - Node.js 22.19.0, esbuild 0.25.12
   - macOS (Darwin 25.6)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to