Skip to content

fix: improve browser/GraalVM compatibility of the parser bundle#1146

Open
armorbreak001 wants to merge 4 commits intoasyncapi:masterfrom
armorbreak001:bounty/1131-browser-bundle-graalvm
Open

fix: improve browser/GraalVM compatibility of the parser bundle#1146
armorbreak001 wants to merge 4 commits intoasyncapi:masterfrom
armorbreak001:bounty/1131-browser-bundle-graalvm

Conversation

@armorbreak001
Copy link
Copy Markdown

Fixes #1131

Problem

The browser bundle (browser/index.js) could not be used in GraalVM's JavaScript engine or other non-browser/non-Node environments because:

  1. node-fetch was bundled inline, which tries to access Node.js globals that don't exist in GraalVM
  2. The webpack globalObject fallback chain didn't include globalThis, causing TypeError: Cannot set property 'X' of undefined
  3. When no fetch implementation was available, the error message was a cryptic module resolution failure

Changes

1. webpack.config.js

  • Externalize node-fetch: Marked as external (commonjs2 null) so it's not bundled. In environments with native fetch (browsers, modern GraalVM), the global fetch API is used instead.
  • Improved globalObject fallback: Added globalThis to the fallback chain (self → globalThis → this) for broader environment support.

2. from.ts

  • Better error handling: When neither global fetch nor node-fetch is available, throw a clear error message explaining what's needed:

    "No fetch implementation available. In Node.js, install 'node-fetch'. In browsers or GraalVM, ensure the global fetch API is available."

How to verify

# Build the browser bundle
cd packages/parser && npm run build:browser

# The bundle should not include node-fetch internals
grep -c "node-fetch" browser/index.js  # should be 0 or minimal

# Test in Node.js (should work as before)
node -e "const p = require('./browser'); console.log(typeof p);"

# For GraalVM: load browser/index.js in GraalVM Context
# and call new AsyncAPIParser().parse('{ asyncapi: "3.0.0", ... }')

Note: For full GraalVM support, users still need to ensure a fetch polyfill is available if their GraalVM version doesn't include one natively. This change makes that integration straightforward by removing the hard dependency on node-fetch.

The ajv-formats uri-reference format validator incorrectly rejects valid URI
references containing square brackets ([, ]), which are legal per RFC 3986 and
RFC 6901. This caused false validation failures for $refs pointing to
components whose keys contain special characters (e.g. JMS message names like
"test:[HandleFirst,HandleSecond]").

Fixes asyncapi#1132
Custom schema parsers were not being triggered for message payloads defined
through an operation's channel reference (operations.*.channel.messages.*).
This path was missing from customSchemasPathsV3.

Fixes asyncapi#1099
The parserapiv1 (parser@^2.1.0) and parserapiv2 (parser@3.0.0-next-major-spec.8)
aliases depend on jsonpath-plus@^7.2.0 which has known vulnerabilities.
Add npm overrides to force jsonpath-plus>=10.0.7 across all nested deps.

Fixes asyncapi#1065
- Externalize node-fetch in webpack browser build (it is Node.js-only)
- Improve globalObject fallback to support GraalVM (no self/globalThis)
- Provide clearer error message when no fetch implementation is available
  instead of failing with a cryptic module resolution error

Fixes asyncapi#1131
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 13, 2026

⚠️ No Changeset found

Latest commit: 1529667

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sonarqubecloud
Copy link
Copy Markdown

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

Successfully merging this pull request may close these issues.

Request: Browser-compatible bundle for Java/GraalVM integration

1 participant