#14789·meteor

[Rspack] meteor test overwrites the dev server's _build/main-dev/server-meteor.js, crashing a concurrent meteor run

Author: perberglandCreated Sep 23, 2026Updated Sep 23, 2026
Labelsmodern-build-stack

Summary

With a meteor run dev server running, starting meteor test in the same app directory crashes the dev server. The test run overwrites the dev server's _build/main-dev/server-meteor.js with the placeholder scaffold. The dev server's watcher sees a server file change and restarts from that placeholder. The placeholder lacks the lazyExternalImports block that makes Meteor link the app's Meteor packages, so the restarted server fails on the first meteor/* import.

#14576 made concurrent dev/test instances stop overwriting each other's *-rspack.js/*-rspack.cjs output bundles. The *-meteor.js mainModule files are still regenerated on every plugin start, and the dev server's server-meteor.js differs from the placeholder once it has compiled.

Versions

  • Meteor 3.5.2
  • rspack package 1.3.0
  • @meteorjs/rspack 2.2.0
  • macOS, Node from the Meteor dev bundle

Steps to reproduce

  1. In an app that uses the Rspack integration and Meteor packages such as aldeed:collection2, start a dev server: meteor run --port 3070
  2. Wait for App running at.
  3. In a second terminal, same directory, run tests on other ports: meteor test --once --driver-package meteortesting:mocha --port 3075 (eager test discovery, no testModule).

What happens

At the moment the test run writes its _build/test/* scaffolds, _build/main-dev/server-meteor.js is rewritten in the same second, and the dev server logs:

=> Server modified -- restarting...
Unhandled rejection: Cannot find package "aldeed:collection2". Try "meteor add aldeed:collection2".
    at Module.__rspackServerModule.require (_build/main-dev/server-meteor.js:29:12)
    at Object.meteor/aldeed:collection2/static (_build/main-dev/server-rspack.cjs:...)
TypeError: collection.attachSchema is not a function
=> Exited with code: 1
=> Your application is crashing. Waiting for file change.

_build/main-dev/server-rspack.cjs is left intact, as #14576 intended. But _build/main-dev/server-meteor.js is back to the placeholder: it ends in /* rspack-server-build-id:initial */ and has no lazyExternalImports() block. Before the test run it held the block (written by RequireExtenalsPlugin) and a timestamped build id (written by bumpServerRuntimeBuildId()).

Expected

A meteor test run in the same directory leaves the dev server's _build/main-dev/* files alone, so the dev server keeps running. The rspack comments in constants.js and build-context.js describe exactly this workflow as supported.

Cause

In packages/rspack/lib/build-context.js, ensureModuleFilesExist() still generates the main scaffolds from a meteor test process. For every file other than an output bundle it overwrites when !existing.includes(defaultContent):

javascript
if (isOutputBundleFile(filename)) {
  return;
}
// ...
if (!existing.includes(defaultContent)) {
  fs.writeFileSync(filePath, defaultContent, 'utf8');
}

After the dev server compiles, its server-meteor.js no longer contains the placeholder verbatim:

  • the /* rspack-server-build-id:initial */ marker has been replaced with a timestamp;
  • the lazyExternalImports function has been appended.

So a test-mode instance always clobbers it.

Possible fixes:

  • From a test-mode process, write main-mode files only when they are missing, leaving existing ones alone.
  • Or compare against the placeholder with the build-id marker and the lazyExternalImports block stripped.

Possibly related

@meteorjs/rspack's persistent cache directory is node_modules/.cache/rspack/<buildContext>-<side>-<mode>. It has no test suffix, so a dev server and a (non-eager) test run in development mode share _build-client-development / _build-server-development. I haven't confirmed that this causes a failure by itself. It may be worth adding the same -test / -app-test suffix used for chunks and assets.