Skip to content

ERR_REQUIRE_ESM: dist/index.js requires ESM-only node-fetch v3 via CommonJS require() — breaks CLI entirely on Node 18-22 #9

Description

@luclinocruz

Bug

Every published version of the postiz npm CLI I tested (2.0.13, 2.0.15, 2.1.0 — latest at time of filing) fails on every command, including --version and auth:status, with:

Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/postiz/node_modules/node-fetch/src/index.js from .../node_modules/postiz/dist/index.js not supported.
Instead change the require of .../node-fetch/src/index.js in .../postiz/dist/index.js to a dynamic import() which is available in all CommonJS modules.
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at Object.<anonymous> (.../postiz/dist/index.js:48:33) {
  code: 'ERR_REQUIRE_ESM'
}

Cause

package.json declares node-fetch: ^3.3.2, which is ESM-only (no CJS build). dist/index.js is itself CommonJS (no "type": "module" in package.json) and calls require('node-fetch') directly instead of either:

  • bundling node-fetch into the CJS output (esbuild/rollup with proper interop), or
  • using a dynamic import(), or
  • pinning to node-fetch@2.x (last CJS-compatible major).

Environment

  • Node.js v22.11.0, Windows 11
  • Installed via npm install -g postiz@2.1.0 (also reproduced on 2.0.13, 2.0.15)

Impact

The CLI is completely unusable out of the box — no command runs, including read-only ones like --version.

Suggested fix

Either bundle the whole dist/index.js (including deps) with esbuild targeting CJS, or pin node-fetch@^2.7.0, or add "type": "module" + convert the entrypoint and shebang accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions