Skip to content

[Feature Request] Support Cloudflare Workers (remove node:module and require) #3568

@y-okady

Description

@y-okady

Target Package

@kintone/rest-api-client

Why

Cloudflare Workers cannot currently load @kintone/rest-api-client.
The Node.js ESM entry (index.mjs) relies on module.createRequire(import.meta.url) and CommonJS loading. The Workers runtime does not provide the Node built-in module (node:module) even when the nodejs_compat flag is enabled, so the package fails to initialize at load time.

In addition, src/platform/node.ts uses require("../../package.json"). Once createRequire is removed, this usage becomes invalid in an ESM context and is also incompatible with Workers.

Supporting Cloudflare Workers is valuable because Workers is a major edge runtime for modern web applications, and enabling this package to run under the official nodejs_compat mode would significantly broaden the environments where the library can be used without any behavioral changes on Node.js.

What

Apply minimal changes that preserve existing Node.js behavior while enabling execution under Cloudflare Workers with nodejs_compat:

Remove the use of module.createRequire from index.mjs and replace it with a pure ESM re-export from the existing ESM entry point.

Replace require("../../package.json") with standard ESM JSON import to avoid dependency on createRequire and to align with Node.js ESM semantics.

Update Node built-in imports in src/platform/node.ts to use the node: prefix (node:fs, node:https, etc.) for better compatibility with Workers’ Node.js compatibility layer.

These changes keep full compatibility with Node.js (the package already requires Node >= 20) and do not modify any runtime behavior of the client, while allowing the package to load successfully in Cloudflare Workers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions