Skip to content

Can't run under Wrangler/Cloudflare Workers #2

@sntran

Description

@sntran

Reporting as an issue, but I understand you may or may not want to tackle it.

Steps to Reproduce

  • Creates a folder
  • Create a _worker.js (content below)
  • Add a "wrangler.json" (content below) to ensure wrangler uses Node.js polyfills.
  • Run npx -y wrangler pages dev .

_worker.js

import { 
  XmlDocument, 
  XsltStylesheet as Stylesheet 
} from "libxslt-wasm";
import { registerModule } from "libxslt-wasm/exslt";

registerModule("common");

export default {
  async fetch(request) {
    const doc = await XmlDocument.fromFileOrUrl(
      "https://dailymed.nlm.nih.gov/dailymed/services/v2/spls/2b4255a7-f9f5-4235-8dbb-b0f03acbd624.xml",
    );
    const stylesheet = await Stylesheet.fromEmbeddedXmlDocument(doc);
    const result = await stylesheet.apply(doc, {});

    return new Response(result.toHtmlString({ format: true }), {
      headers: {
        "Content-Type": "text/html; charset=utf-8",
      },
    });
  },
}

wrangler.json

{
  "name": "test",
  "compatibility_flags": [
    "nodejs_compat"
  ],
  "compatibility_date": "2025-09-23"
}

Expected Result

See the transformed HTML on "http://localhost:8788/"

Actual Result

Wrangler throws an error in the shell:

[ERROR] service core:user:test: Uncaught TypeError: The argument 'path' The argument must be a file URL object, a file URL string, or an absolute path string.. Received 'undefined'

    at null.<anonymous> (node:module:12:15) in createRequire
    at null.<anonymous> (bundledWorker-0.5924026434449623.js:2421:42) in createRequire
    at null.<anonymous> (bundledWorker-0.5924026434449623.js:2756:22

Tracing Notes

The error is traced to line 59 of "dist/output/libxslt.js":

var require = createRequire(import.meta.url);

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions