Skip to content

[Bug]: Code execution order changed after bundling #1519

@chenjiahan

Description

@chenjiahan

Version

System:
    OS: macOS 26.2
    CPU: (16) arm64 Apple M3 Max
    Memory: 3.42 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 145.0.7632.160
    Safari: 26.2
  npmPackages:
    @rslib/core: ^0.19.6 => 0.19.6

Details

src/index.ts

import "./check";
import * as util from "node:util";

console.log(util.styleText);

src/check.ts

function checkNodeVersion() {
  const [major] = process.versions.node.split(".");
  if (parseInt(major) < 20) {
    throw new Error("Node.js version must be >= 20");
  }
}

checkNodeVersion();

Expected output (esbuild output)

// src/check.ts
function checkNodeVersion() {
  const [major] = process.versions.node.split(".");
  if (parseInt(major) < 20) {
    throw new Error("Node.js version must be >= 20");
  }
}
checkNodeVersion();

// src/index.ts
import * as util from "node:util";
console.log(util.styleText);
Image

Current output (Rslib)

import { styleText } from "node:util";
function checkNodeVersion() {
    const [major] = process.versions.node.split(".");
    if (parseInt(major) < 20) throw new Error("Node.js version must be >= 20");
}
checkNodeVersion();
console.log(styleText);
Image

Reproduce link

https://github.com/chenjiahan/rslib-repro-import-order

Reproduce Steps

  1. pnpm i
  2. pnpm build
  3. pnpm build:esbuild

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions