Skip to content

[Bug]: ReferenceError: module is not defined when using Rspack 1.5.6 with Rslib #1239

@colinaaa

Description

@colinaaa

Version

System:
    OS: Linux 5.15 veLinux GNU/Linux 2 (lyra) 2 (lyra)
    CPU: (64) x64 Intel(R) Xeon(R) Platinum 8457C
    Memory: 244.96 GB / 251.61 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 24.6.0 - /run/user/1001/fnm_multishells/3028163_1758543342952/bin/node
    npm: 11.5.1 - /run/user/1001/fnm_multishells/3028163_1758543342952/bin/npm
    pnpm: 10.15.1 - /run/user/1001/fnm_multishells/3028163_1758543342952/bin/pnpm
  npmPackages:
    @rslib/core: ^0.13.3 => 0.13.3 (with @rspack/core overrides to 1.5.6)

Details

When having source code like this:

import module from 'node:module'

export function register(options) {
  if (!module.register) {
    /** code */
  }
  module.register(/** code */)
}

When building with Rslib (with @rspack/core v1.5.6), it would become

import node_module from 'node:module'

export function register(options) {
  if (!module.register) {
    /** code */
  }
  node_module.register(/** code */)
}

The module in the if is not renamed to node_module.

You may see an real world example at: https://github.com/lynx-family/lynx-stack/actions/runs/17916170863/job/50939912914

This issue does not exist when using @rspack/core v1.5.5.

Reproduce link

https://github.com/colinaaa-reproductions/rspack-repro-module-rename

Reproduce Steps

  1. pnpm install
  2. pnpm run build

You may see that only the output of Rslib is incorrect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions