rolldown: Watch mode seems to hang in larger project

Discussed in https://github.com/rolldown/rolldown/discussions/3889

<div type='discussions-op-text'>

Originally posted by tbrannam March 18, 2025 We’re seeing impressive build time improvements when porting from Rollup to Rolldown, but when we attempt to use --watch mode in the build environment, we see Rolldown not complete building the output.

I’m sure there’s something specific to the environment or codebase, as watch seems to work fine in a trivial example.

The output from the cli

Waiting for changes...                                                                                                                                                                                                                                                                                                              
✔ Rebuilt lib/web/esm in 1.04 s.                                                                                                                                                                                                                                                                                                   
Found src/web/fragment.tsx changed, rebuilding...                                                                                                                                                                                                                                                                                   

From the console it seems that our project does not finish rebuilding, manually inspecting the output file we can see that source changes are not emitted.

I’ve attempted to set RD_LOG and the volume of output is very large, so I won’t post it here without some guidance of what is helpful to narrow this down.

I’ve tried adding some exclusions to the watch.exclude property, and I’ve hacked the source code to remove any Rollup plugins from the build environment.

Please chime in if you have some suggestions on how to narrow down the problem.

</div>

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (6 by maintainers)

Commits related to this issue

Most upvoted comments

That seems to only occur when the main process is watching a lot of files, as ignoring node_modules fixed it. I assume this is more closely related to process load causing build to take longer. This makes a lot of sense, and I’m wondering if it’s tied to this issue.

In the meantime, I scrapped together a watch script:

import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';

function watchDirRecursive(dir: string, ignored: string[], onChange: () => void) {
    if (ignored.includes(dir)) return;

    const watcher = fs.watch(dir, { persistent: true }, (_eventType, filename) => {
        if (filename) {
            const fullPath = path.join(dir, filename);

            fs.stat(fullPath, (err, stats) => {
                if (!err && stats.isDirectory()) {
                    watchDirRecursive(fullPath, ignored, onChange);
                }
            });

            onChange();
        }
    });

    fs.readdir(dir, { withFileTypes: true }, (err, files) => {
        if (err) return;
        for (const file of files) {
            if (file.isDirectory()) watchDirRecursive(path.join(dir, file.name), ignored, onChange);
        }
    });

    return watcher;
}

const currentDir = import.meta.dirname;

const ignore = [
    `${currentDir}/node_modules`,
    `${currentDir}/dist`, // or whatever your dist directory is...parsing vite.config.ts sounds irritating
];

console.log(`\x1b[34mwatching for changes\n\x1b[0m`);

const build = () => {
    execSync(`cd ${currentDir} && bunx --bun vite build`, { stdio: 'inherit' });
    console.log('');
}

build()

watchDirRecursive(currentDir, ignore, () => build)

It goes in the root directory and forces you to manually configure. If you don’t use bun, take that part out. However, it works, which is a good upgrade IMO

edit 1: listen for file changes in directories created after script run edit 2: run the build on command run like normal watch, wrote on ios so probably has no syntax errors

Mostly in https://github.com/hcampos-professional/rolldown-repro-3890

  1. Checkout the repo
  2. Run npm i
  3. Run node rolldown.mjs - notice that the build takes a significant amount of time to complete
  4. Modify lines 16-17 in rolldown.mjs to include only one or a few files - notice how much faster the compilation is.

For 3 and 4 above, you can also try to modify one of the files in src (e.g. by adding a console.log()) and see that rebuilds are also slower the more files are included in the watch.

The expectation is that the number of watched files shouldn’t have an impact in the compilation or recompilation. The initial build with watch should at most take the same time as just using build from rolldown, and subsequent rebuilds should be faster.