Skip to content

fix: move webpack/rspack helper file out of outDir#305

Merged
yoannmoinet merged 2 commits intomasterfrom
yoann/fix-webpack-helper
Apr 6, 2026
Merged

fix: move webpack/rspack helper file out of outDir#305
yoannmoinet merged 2 commits intomasterfrom
yoann/fix-webpack-helper

Conversation

@yoannmoinet
Copy link
Copy Markdown
Member

What and why?

Fixes #304.

When output.clean: true is set in webpack/rspack, the CleanPlugin deletes the injection helper file (__datadog-helper-file.js) from the output directory during emit. On subsequent rebuilds (watch/dev mode), module resolution fails because the file no longer exists — apply() only runs once at compiler creation, so the file is never recreated.

How?

Move the helper file from context.bundler.outDir to node_modules/.cache/datadog-build-plugins/ inside the project root. This location is:

  • Inside the project root — webpack/rspack can resolve it as an entry point
  • Outside the output directoryoutput.clean can't delete it
  • Already gitignored — lives under node_modules/
  • Conventionalnode_modules/.cache/ is the standard cache location for build tools

Also adds a clean option to the test infrastructure's BundlerConfig, wired to output.clean (webpack/rspack) and build.emptyOutDir (Vite).

The regression test creates a compiler once and runs it twice without closing — simulating watch/dev mode. Without the fix, the second build fails with a resolution error.

When output.clean is enabled, webpack/rspack deletes the helper file
from outDir during emit. On subsequent rebuilds (watch/dev mode),
module resolution fails because the file is gone.

Move the helper file to node_modules/.cache/datadog-build-plugins/
inside the project root — still resolvable by webpack/rspack, but
outside the output directory so output.clean can't delete it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@yoannmoinet yoannmoinet enabled auto-merge April 5, 2026 13:45
@yoannmoinet yoannmoinet disabled auto-merge April 6, 2026 13:39
@yoannmoinet yoannmoinet merged commit 6b879a8 into master Apr 6, 2026
4 checks passed
@yoannmoinet yoannmoinet deleted the yoann/fix-webpack-helper branch April 6, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't resolve '/Users/zzzzz/git/www/yyyyy/dist/webpack.1.__datadog-helper-file.js' - webpack output.clean

2 participants