Skip to content

Bundled Output Missing core.cjs File When Using esbuild with zx Library #894

@shetz163

Description

@shetz163

🐛 Bug Report

Problem Description

I encountered an issue when using esbuild to bundle a project that imports the zx library. The bundled output file fails to run due to the absence of the core.cjs file, which is required by the zx library.


Steps to Reproduce

  1. Create a TypeScript file that imports the zx library.
  2. Use esbuild to bundle the file.
  3. Attempt to run the bundled JavaScript output.

Expected Behavior

The bundled JavaScript file should run without errors, and the functionality from the zx library should work as expected.


Actual Behavior

After bundling with esbuild, the generated JavaScript file does not include the necessary core.cjs file, leading to runtime errors.


Reproduction Files

  • Original TypeScript file:
import { $ } from 'zx/core';
const main = async () => {
  const list = ['5', '10', '15', '20', '25'];
  for (const item of list) {
    console.log(`${item} start`);
    await $`sleep ${item}`;
    console.log(`${item} end`);
  }
}
main();
  • Bundled JavaScript file:
"use strict";

// node_modules/.pnpm/zx@8.1.6/node_modules/zx/build/deno.js
var import_node_module = require("node:module");
var import_meta = {};
var require2 = (0, import_node_module.createRequire)(import_meta.url);
var __filename = new URL(import_meta.url).pathname;
var __dirname = new URL(".", import_meta.url).pathname;
if (globalThis.Deno) {
  globalThis.require = require2;
  globalThis.__filename = __filename;
  globalThis.__dirname = __dirname;
}

// node_modules/.pnpm/zx@8.1.6/node_modules/zx/build/core.js
var {
  $,
  ProcessOutput,
  ProcessPromise,
  cd,
  defaults,
  kill,
  log,
  syncProcessCwd,
  useBash,
  usePowerShell,
  usePwsh,
  within
} = require2("./core.cjs");

// test.ts
var main = async () => {
  const list = ["5", "10", "15", "20", "25"];
  for (const item of list) {
    console.log(`${item} start`);
    await $`sleep ${item}`;
    console.log(`${item} end`);
  }
};
main();

Build Command

The command used for bundling:
esbuild ./test.ts --bundle --outfile=out.js --platform=node --target=node18

Specifications

  • zx version: 8.1.6
  • Platform: macos
  • Runtime: node

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