Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
shetz163 opened this issue Sep 15, 2024 · 1 comment
Closed

Comments

@shetz163
Copy link

🐛 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/[email protected]/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/[email protected]/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
@antongolub
Copy link
Collaborator

I'm afraid, the issue is on esbuild's side: evanw/esbuild#1828

@google google locked and limited conversation to collaborators Sep 15, 2024
@antonmedv antonmedv converted this issue into discussion #895 Sep 15, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants