Skip to content

fix: remove node:module/require and update import statements to use node: prefix#3567

Open
y-okady wants to merge 1 commit intokintone:mainfrom
c-tag:fix/replace-require-to-support-cf-workers
Open

fix: remove node:module/require and update import statements to use node: prefix#3567
y-okady wants to merge 1 commit intokintone:mainfrom
c-tag:fix/replace-require-to-support-cf-workers

Conversation

@y-okady
Copy link

@y-okady y-okady commented Jan 17, 2026

Why

#3568

What

How to test

Checklist

  • Read CONTRIBUTING.md
  • Updated documentation if it is required.
  • Added tests if it is required.
  • Passed pnpm lint and pnpm test on the root directory.

@y-okady y-okady requested a review from a team as a code owner January 17, 2026 02:59
@y-okady y-okady requested review from chihiro-adachi, Copilot and tasshi-me and removed request for a team January 17, 2026 02:59
@github-actions github-actions bot added the pkg: rest-api-client @kintone/rest-api-client label Jan 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes the module import statements in the rest-api-client package by adding the node: prefix to Node.js built-in module imports and replacing a CommonJS require statement with an ES module import.

Changes:

  • Updated all Node.js built-in module imports in node.ts to use the node: prefix (fs, util, path, https, os)
  • Converted package.json import from CommonJS require() to ES module import statement in node.ts
  • Simplified index.mjs to directly export from the ESM build instead of using module.createRequire

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/rest-api-client/src/platform/node.ts Added node: prefix to built-in module imports and converted package.json from require to import
packages/rest-api-client/index.mjs Simplified to directly export from ESM build, removing module.createRequire pattern

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hisasami
Copy link
Contributor

@y-okady
Thank you for your PR. There seems to be an issue when executing as ES module. Could you please check this out?
CJS works fine.

Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
To eliminate this warning, add "type": "module" to /Users/xxx/workspace/js-sdk/packages/rest-api-client/esm/package.json.
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/modules/esm/resolve:262
    throw new ERR_UNSUPPORTED_DIR_IMPORT(path, basePath, String(resolved));
          ^

@y-okady
Copy link
Author

y-okady commented Jan 29, 2026

@hisasami
Thank you for your review.

I tested the package execution in both CommonJS (CJS) and ES Modules (ESM) environments without any changes from this PR.

CJS works fine when executed with node index.cjs:

// index.cjs
const { KintoneRestAPIClient } = require("@kintone/rest-api-client");

However, ESM does not work when executed with node index.mjs:

// index.mjs
import { KintoneRestAPIClient } from "@kintone/rest-api-client";

This results in the following error:

node:internal/modules/esm/resolve:262
    throw new ERR_UNSUPPORTED_DIR_IMPORT(path, basePath, String(resolved));
          ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/okady/workspace/c-tag/js-sdk-test/node_modules/@kintone/rest-api-client/esm/src/platform/' is not supported resolving ES modules imported from /Users/okady/workspace/c-tag/js-sdk-test/node_modules/@kintone/rest-api-client/esm/src/index.js
    at finalizeResolution (node:internal/modules/esm/resolve:262:11)
    at moduleResolve (node:internal/modules/esm/resolve:864:10)
    at defaultResolve (node:internal/modules/esm/resolve:990:11)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:718:20)
    at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:735:38)
    at ModuleLoader.resolveSync (node:internal/modules/esm/loader:764:52)
    at #resolve (node:internal/modules/esm/loader:700:17)
    at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:620:35)
    at ModuleJob.syncLink (node:internal/modules/esm/module_job:143:33)
    at ModuleJob.link (node:internal/modules/esm/module_job:228:17) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///Users/okady/workspace/c-tag/js-sdk-test/node_modules/@kintone/rest-api-client/esm/src/platform/'
}

This error appears to originate from the existing implementation in the SDK (specifically the import in src/index.ts#L1), which is outside the scope of the changes introduced in this PR.

Would you like me to address this issue as part of this PR, or should it be handled separately?

@hisasami
Copy link
Contributor

hisasami commented Mar 3, 2026

@y-okady
Sorry for the late response. Yes, we appreciate it if you would include this issue in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: rest-api-client @kintone/rest-api-client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants