Bun's bundler mis-compiles `import * as tmp from 'tmp'`. tmp's entrypoint ends with `Object.defineProperty(module.exports, 'tmpdir', {...})`. When bun builds an ESM namespace object for that CJS module it emits a reference to `exports_tmp` without ever declaring the binding, so the compiled binary dies on startup with `ReferenceError: exports_tmp is not defined`. Importing it as CJS instead keeps bun on its `__commonJS` path, which handles the `defineProperty` pattern correctly. Only the `tmp.file` value and the `Options` type are used here, so the switch is behaviour-preserving. diff --git a/src/util/fs.ts b/src/util/fs.ts index 21c99ef..0d2224f 100644 --- a/src/util/fs.ts +++ b/src/util/fs.ts @@ -1,6 +1,7 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as tmp from 'tmp'; +import type { Options as TmpOptions } from 'tmp'; +const tmp: typeof import('tmp') = require('tmp'); import { lookpath } from 'lookpath'; import { isErrorLike } from '@httptoolkit/util'; @@ -62,7 +63,7 @@ export const resolveCommandPath = (path: string): Promise => export const commandExists = (path: string): Promise => resolveCommandPath(path).then((result) => result !== undefined); -export const createTmp = (options: tmp.Options = {}) => new Promise<{ +export const createTmp = (options: TmpOptions = {}) => new Promise<{ path: string, fd: number, cleanupCallback: () => void