Skip to content
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

[Bug]: "should have module" panic #9534

Open
jeffijoe opened this issue Mar 3, 2025 · 5 comments
Open

[Bug]: "should have module" panic #9534

jeffijoe opened this issue Mar 3, 2025 · 5 comments

Comments

@jeffijoe
Copy link

jeffijoe commented Mar 3, 2025

System Info

System:
OS: macOS 15.3.1
CPU: (10) arm64 Apple M1 Max
Memory: 650.28 MB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.12.1 - ~/.nvm/versions/node/v20.12.1/bin/node
npm: 10.8.1 - ~/.nvm/versions/node/v20.12.1/bin/npm
pnpm: 9.10.0 - ~/.nvm/versions/node/v20.12.1/bin/pnpm
Browsers:
Chrome: 133.0.6943.142
Safari: 18.3
Safari Technology Preview: 18.4

Details

The ts-checker-rspack-plugin crashes randomly when performing Git operations such as rebase, checkout, etc. I suspect it is due to multiple files changing concurrently. I originally opened this issue on the ts-checker-rspack-plugin repo, but was asked to open the issue here.

Message:  should have module
Location: crates/rspack_core/src/compiler/module_executor/execute.rs:81

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 1: _napi_register_module_v1
    at <unknown source file>
 2: _napi_register_module_v1
    at <unknown source file>
 3: _napi_register_module_v1
    at <unknown source file>
 4: _napi_register_module_v1
    at <unknown source file>
 5: _wasmer_vm_f64_nearest
    at <unknown source file>
 6: _wasmer_vm_f64_nearest
    at <unknown source file>
 7: _napi_register_module_v1
    at <unknown source file>
 8: _napi_register_module_v1
    at <unknown source file>
 9: _napi_register_module_v1
    at <unknown source file>
10: _napi_register_module_v1
    at <unknown source file>
11: _napi_register_module_v1
    at <unknown source file>
12: _napi_register_module_v1
    at <unknown source file>
13: _napi_register_module_v1
    at <unknown source file>
14: _napi_register_module_v1
    at <unknown source file>
15: __pthread_deallocate
    at <unknown source file>
Error: write EPIPE
    at target._send (node:internal/child_process:879:20)
    at target.send (node:internal/child_process:752:19)
    at /Users/jeff.hansen/Projects/my-app/node_modules/.pnpm/ts-checker-rspack-plugin@1.1.1_@rspack+core@1.2.3_@swc+helpers@0.5.15__typescript@5.7.3/node_modules/ts-checker-rspack-plugin/lib/rpc/expose-rpc.js:18:31
    at new Promise (<anonymous>)
    at sendMessage (/Users/jeff.hansen/Projects/my-app/node_modules/.pnpm/ts-checker-rspack-plugin@1.1.1_@rspack+core@1.2.3_@swc+helpers@0.5.15__typescript@5.7.3/node_modules/ts-checker-rspack-plugin/lib/rpc/expose-rpc.js:10:38)
    at process.handleMessage (/Users/jeff.hansen/Projects/my-app/node_modules/.pnpm/ts-checker-rspack-plugin@1.1.1_@rspack+core@1.2.3_@swc+helpers@0.5.15__typescript@5.7.3/node_modules/ts-checker-rspack-plugin/lib/rpc/expose-rpc.js:51:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

Reproduce link

No response

Reproduce Steps

When running in dev/watch mode in a project with a few Git commits that affect multiple files, check out commits fast enough, and eventually, the plugin will crash.

@chenjiahan
Copy link
Member

Can you provide a minimal reproduction? thank you

@chenjiahan chenjiahan added need reproduction and removed pending triage The issue/PR is currently untouched. labels Mar 3, 2025
Copy link
Contributor

github-actions bot commented Mar 3, 2025

Hello @jeffijoe, sorry we can't investigate the problem further without reproduction demo, please provide a repro demo by forking rspack-repro, or provide a minimal GitHub repository by yourself. Issues labeled by need reproduction will be closed if no activities in 14 days.

@jeffijoe
Copy link
Author

jeffijoe commented Mar 3, 2025

I'm trying to reproduce it minimally, but I think it needs to be a large enough codebase for the issue to manifest. I'll keep trying.

@jeffijoe
Copy link
Author

jeffijoe commented Mar 3, 2025

@chenjiahan for more context, I am self-hosting the Rsbuild dev server for a Koa backend, would there be any problem with the following middleware (race conditions)? Or are there any betters APIs to generate the assets markup for rendering in a view? If any APIs here are unsafe to call in a server middleware, then that would help me narrow down how to reproduce it minimally.

import type Koa from 'koa'
import koaConnect from 'koa-connect'
import { type AssetsMarkup, type ServerCallback } from '../lib/server.js'
import fs from 'node:fs'
import path from 'node:path'

export interface RsbuildMiddlewareOptions {
  /**
   * Method that allows the middleware to access the HTTP server
   * when it becomes available.
   */
  onServer: (callback: ServerCallback) => void
}

/**
 * Runs the Rsbuild dev server (powered by Rspack, powered by Rust).
 *
 * @param options
 */
export function rsbuild(options: RsbuildMiddlewareOptions): Koa.Middleware {
  const rsbuildPromise = import('@rsbuild/core').then(
    async ({ createRsbuild, loadConfig }) => {
      const rsbuildInstance = await createRsbuild({
        rsbuildConfig: await loadConfig().then((c) => c.content),
      })

      const rsbuildDevServer = await rsbuildInstance.createDevServer({
        runCompile: true,
      })

      options.onServer((server) => {
        rsbuildDevServer.connectWebSocket({ server })
      })

      const wrappedDevMiddleware = koaConnect((req, res, next) =>
        rsbuildDevServer.middlewares(req, res, next),
      )

      return {
        wrappedDevMiddleware,
        rsbuildInstance,
        rsbuildDevServer,
      }
    },
  )

  return async function rsbuildMiddleware(ctx, next) {
    const { wrappedDevMiddleware, rsbuildDevServer } = await rsbuildPromise

    // Set the status to 200 in case the dev middleware is the last one
    // to run. This is because it doesn't set the status for some reason.
    ctx.status = 200

    // Call the dev server middleware.
    await wrappedDevMiddleware(ctx, async () => {
      // Set it back just in case.
      ctx.status = 404

      // If we reach this point, the dev server middleware isn't
      // serving an asset, so we can add asset info to the context.
      const compilation = await rsbuildDevServer.environments.web
        .getStats()
        .then((s) => s.compilation)

      const compilationAssets = compilation.getAssets()
      if (!compilationAssets) {
        throw new Error('Rsbuild did not return any assets.')
      }

      const jsAssets: string[] = []
      const cssAssets: string[] = []
      for (const asset of compilationAssets) {
        try {
          // Don't include lazy-loaded assets.
          if (asset.name.includes('/async/')) {
            continue
          }

          if (asset.name.endsWith('.css')) {
            cssAssets.push(`<link rel="stylesheet" href="/${asset.name}">`)
            continue
          }

          if (asset.name.endsWith('.js')) {
            if ('info' in asset && asset.info.hotModuleReplacement) {
              // Ignore HMR updates when generating the initial asset list.
              continue
            }

            jsAssets.push(`<script defer src="/${asset.name}"></script>`)
          }
        } catch (err: unknown) {
          console.error('Unable to process asset', asset, err)
        }
      }

      // Makes the assets available to the subsequent `views` middleware.
      ctx.state.devServerAssets = [...cssAssets, ...jsAssets].join('\n')

      return next()
    })
  }
}

@jeffijoe
Copy link
Author

jeffijoe commented Mar 3, 2025

@chenjiahan I may have made another observation - do you know if there would be any issue with running the app dev server and an Rsbuild Storybook simultaneously? For example, does the TS Checker rely on some shared state that may be namespaced based on the current working directory? I'm still testing this theory, but I noticed that I didn't observe the issue when I was only running my app dev server, but when I started the Storybook one alongside it, both of them crashed at the same time after I did a Git rebase. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants