Skip to content

TypeError: open is not a function on Node 18+ (ESM interop issue) #33

@nternovoy

Description

@nternovoy

Bug

Running poki upload on Node 18+ throws:

TypeError: open is not a function
at Server. (.../node_modules/@poki/cli/bin/index.js:288:29)

Root Cause

open v10+ is ESM-only. The rollup config in rollup.config.mjs marks open as external, so the bundled CJS output emits:

var open = require('open');

When Node loads an ESM-only package via require(), it returns { default: fn } instead of fn directly. So open(url) fails because open is an object, not a function.

Reproduction

  node -e "const open = require('open'); console.log(typeof open, typeof open.default)"
  # Output: object function

  npx @poki/cli upload --name "test"
  # TypeError: open is not a function

Tested on Node v24.14.0, @poki/cli v0.1.18, Windows 10 (Git Bash). Likely affects all platforms on Node 18+.

Suggested Fix

Option A: Pin open to v9, the last CJS-compatible version:

  - "open": "^11.0.0"
  + "open": "^9.1.0"

Option B: Remove open from the external array in rollup.config.mjs so rollup bundles it and handles ESM→CJS interop internally.

Option C: Use dynamic import() in src/auth.ts:

- import open from 'open'
+ const open = (await import('open')).default

Workaround

Patch node_modules/@poki/cli/bin/index.js line 11:

  - var open = require('open');
  + var _open = require('open');
  + var open = typeof _open === 'function' ? _open : _open.default;

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