rsdoctor icon indicating copy to clipboard operation
rsdoctor copied to clipboard

[Bug]: RangeError: Maximum call stack size exceeded

Open morganney opened this issue 4 months ago • 5 comments

Version

System:
    OS: macOS 15.6
    CPU: (14) arm64 Apple M4 Pro
    Memory: 5.83 GB / 24.00 GB
    Shell: 3.2.57 - /bin/bash
  Browsers:
    Chrome: 139.0.7258.66
    Safari: 18.6


devDependencies:
@rsdoctor/rspack-plugin 1.2.1
@rspack/cli 1.4.11
@rspack/core 1.4.11


Node v22.17.1

Details

Trying to run rsdoctor and getting OOM errors and/or RangeError: Maximum call stack size exceeded errors. Additionally, the build seems to not finish, or not finish completely (not sure).

At times I can load the report page and it will show these errors:

ERROR  × Module build failed:
  ╰─▶   ×   × Module build failed:
        │   ╰─▶   × RangeError: Maximum call stack size exceeded
        │         │     at /Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@rsdoctor/sdk/dist/cjs/sdk/sdk/index.js:217:42
        │         │     at Array.forEach (<anonymous>)
        │         │     at RsdoctorSDK.reportLoader (/Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@rsdoctor/sdk/dist/cjs/sdk/sdk/index.js:210:18)
        │         │     at RsdoctorSDK.reportLoaderStartOrEnd (/Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@rsdoctor/sdk/dist/cjs/sdk/sdk/index.js:242:26)
        │         │     at Object.loaderModule (/Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@rsdoctor/core/dist/build-utils/build/loader/probeLoader.js:78:9)
        │         │     at /Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@rspack/core/dist/index.js:3050:29
        │         │     at node:internal/util:472:21
        │         │     at new Promise (<anonymous>)
        │         │     at node:internal/util:458:12
        │         │     at isomorphoicRun (/Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@rspack/core/dist/index.js:3549:244)

I use the builtin:swc-loader like this:

{
  test: /\.m?[jt]sx?$/,
  exclude: /node_modules/,
  loader: 'builtin:swc-loader',
  options: {
    jsc: {
      parser: {
        syntax: 'typescript',
        jsx: true,
        decorators: true,
        decoratorsBeforeExport: true,
        dynamicImport: true,
      },
      transform: {
        legacyDecorator: true,
        decoratorMetadata: false,
        useDefineForClassFields: false,
        react: {
          runtime: 'automatic',
        },
      },
    },
    env: {
      targets: pkg.browserslist,
    },
  },
}

I use the rsdoctor plugin like this:

import {RsdoctorRspackPlugin} from '@rsdoctor/rspack-plugin';

new RsdoctorRspackPlugin({
  port: 8081,
})

<img width="1679" height="851" alt="Image" src="https://github.com/user-attachments/assets/51bd26a0-dc6c-40e2-87d8-281d625b3355" />

With the Activity Monitor app open I can see the memory increase for the rspack-node process. The build runs fine without using rsdoctor.

Possibly related to #1080

Reproduce link

N/A

Reproduce Steps

I don't have a repro link or example as this is a private project for work. This error did not occur before switching over to builtin:swc-loader. Before we were using esbuild-loader.

morganney avatar Aug 09 '25 17:08 morganney

Here's what an OOM error looks like:

morgan@mactop ~/code/vortex-app/frontend (chore/build-target)$ pnpm build:doctor

> [email protected] build:doctor /Users/morgan/code/vortex-app/frontend
> pnpm --filter vortex-frontend run build:doctor


> [email protected] build:doctor /Users/morgan/code/vortex-app/frontend/apps/vortex
> NODE_ENV=production RSDOCTOR=true rspack build


<--- Last few GCs --->

[1844:0x158008000]   137939 ms: Mark-Compact 4042.4 (4140.1) -> 4031.8 (4142.6) MB, pooled: 0 MB, 1169.25 / 0.00 ms  (average mu = 0.221, current mu = 0.104) task; scavenge might not succeed
[1844:0x158008000]   139484 ms: Mark-Compact 4044.7 (4142.6) -> 4034.1 (4144.8) MB, pooled: 0 MB, 1407.75 / 0.00 ms  (average mu = 0.149, current mu = 0.089) task; scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

 1: 0x100359cac node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/Users/morgan/n/bin/node]
 2: 0x10052f998 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/Users/morgan/n/bin/node]
 3: 0x10073f0c0 v8::internal::Heap::stack() [/Users/morgan/n/bin/node]
 4: 0x10073d460 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/morgan/n/bin/node]
 5: 0x100791e60 v8::internal::MinorGCJob::Task::RunInternal() [/Users/morgan/n/bin/node]
 6: 0x1003d95e0 node::PerIsolatePlatformData::RunForegroundTask(std::__1::unique_ptr<v8::Task, std::__1::default_delete<v8::Task>>) [/Users/morgan/n/bin/node]
 7: 0x1003d8554 node::PerIsolatePlatformData::FlushForegroundTasksInternal() [/Users/morgan/n/bin/node]
 8: 0x100f3a974 uv__async_io [/Users/morgan/n/bin/node]
 9: 0x100f4ed0c uv__io_poll [/Users/morgan/n/bin/node]
10: 0x100f3aedc uv_run [/Users/morgan/n/bin/node]
11: 0x10025a4f4 node::SpinEventLoopInternal(node::Environment*) [/Users/morgan/n/bin/node]
12: 0x1003a4e74 node::NodeMainInstance::Run() [/Users/morgan/n/bin/node]
13: 0x100315008 node::Start(int, char**) [/Users/morgan/n/bin/node]
14: 0x196486b98 start [/usr/lib/dyld]
/Users/morgan/code/vortex-app/frontend/apps/vortex:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  [email protected] build:doctor: `NODE_ENV=production RSDOCTOR=true rspack build`
Command failed with signal "SIGABRT"
 ELIFECYCLE  Command failed.
Abort trap: 6

morganney avatar Aug 09 '25 17:08 morganney

Is this issue present in rsdoctor v1.1.10 as well?

yifancong avatar Aug 10 '25 13:08 yifancong

Yes, same stack trace:

  × Module build failed:
  ╰─▶   ×   × Module build failed:
        │   ╰─▶   × RangeError: Maximum call stack size exceeded
        │         │     at /Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@rsdoctor/sdk/dist/cjs/sdk/sdk/index.js:171:23
        │         │     at Array.forEach (<anonymous>)
        │         │     at RsdoctorSDK.reportLoader (/Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@rsdoctor/sdk/dist/cjs/sdk/sdk/index.js:160:10)
        │         │     at RsdoctorSDK.reportLoaderStartOrEnd (/Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@rsdoctor/sdk/dist/cjs/sdk/sdk/index.js:205:14)
        │         │     at Object.loaderModule (/Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@rsdoctor/core/dist/build-utils/build/loader/probeLoader.js:70:7)
        │         │     at /Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@rspack/core/dist/index.js:3050:29
        │         │     at node:internal/util:472:21
        │         │     at new Promise (<anonymous>)
        │         │     at node:internal/util:458:12
        │         │     at isomorphoicRun (/Users/morgan/code/vortex-app/frontend/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@rspack/core/dist/index.js:3549:244)

morganney avatar Aug 10 '25 13:08 morganney

It appears to be something with rsdoctor and builtin:swc-loader as the issue only happens when using the builtin swc-loader.

Here's a summary from cursor:

This "Maximum call stack size exceeded" error (RangeError) from Rsdoctor when used with builtin:swc-loader in Rspack is a known issue in the Rspack/Rsdoctor ecosystem, especially when using the SWC loader for TypeScript/JSX transpilation.

Why does this happen?

  • Rsdoctor is a diagnostic plugin for Rspack/Webpack that hooks deeply into the loader pipeline to collect build insights.
  • builtin:swc-loader is Rspack's built-in loader for transpiling TypeScript/JSX using SWC.
  • When Rsdoctor is enabled, it wraps loader calls to monitor them. In some cases, especially with SWC, this can cause recursive calls or circular references, leading to a stack overflow (infinite recursion).
  • The stack trace shows the error is in RsdoctorSDK.reportLoader and reportLoaderStartOrEnd, which are called for every loader invocation. If the loader or plugin setup is not careful, this can recurse indefinitely.

Why is it out of memory?

  • The stack overflow (maximum call stack size exceeded) is a form of out-of-memory error: the process runs out of stack space due to infinite recursion, not heap memory.

Is this a bug?

  • Yes, this is a bug in the interaction between Rsdoctor and the SWC loader in Rspack. It is not a misconfiguration on your part.
  • This is a known issue in the Rspack and Rsdoctor GitHub issues:
  • The root cause is that Rsdoctor's loader instrumentation is not fully compatible with the way builtin:swc-loader is invoked internally by Rspack.

Workarounds

  1. Disable Rsdoctor in development
    Only enable Rsdoctor in production builds or when you are not using the SWC loader.
    In your rspack.config.js, you already have:

    process.env.RSDOCTOR &&
      new RsdoctorRspackPlugin({
        port: 8081,
        exclude: [/node_modules/],
        experiments: {enableNativePlugin: true},
      }),
    

    Make sure RSDOCTOR is not set in your environment when running development builds with SWC.

  2. Remove Rsdoctor temporarily
    If you need to use SWC, comment out or remove the Rsdoctor plugin from your config until the bug is fixed upstream.

  3. Use a different loader
    If you must use Rsdoctor, try using a different loader (like Babel) for JS/TS, though this may not be ideal for performance.

  4. Watch for upstream fixes
    Track the issues above for updates. The maintainers are aware and may release a fix in future versions.

Summary Table

Tool/Plugin Status with Rsdoctor
builtin:swc-loader ❌ Stack overflow
babel-loader ✅ Usually works
ts-loader ✅ Usually works

In short:
This is a known incompatibility between Rsdoctor and Rspack's SWC loader. Disable Rsdoctor when using SWC, or use a different loader if you need Rsdoctor's diagnostics. Watch the linked issues for a fix.

Let me know if you want a code snippet to conditionally disable Rsdoctor, or if you want to see how to switch loaders!

morganney avatar Aug 10 '25 17:08 morganney

If I use swc-loader (not the builtin) it works fine.

morganney avatar Aug 10 '25 17:08 morganney