web-infra-dev / web-infra-dev/rslib

[Bug]: Code execution order changed after bundling

Open
#1,519 0 comments 0 reactions 1 assignee View on GitHub

@JSerFeng is already working on this.

Since Mar 8, 2026.

Rspack
Dominant language
TypeScript
Stars
1k
Forks
67
Avg merge
6h 9m
Merged PRs (30d)
57

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.