-
Notifications
You must be signed in to change notification settings - Fork 4
TypeError: open is not a function on Node 18+ (ESM interop issue) #33
Description
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 functionTested 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')).defaultWorkaround
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;