feat: validate output target in Rsbuild config#5592
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds early validation for the output.target setting in Rsbuild configurations and updates E2E scripts to normalize error messages and cover invalid-target scenarios.
- Refactored environment name checks and introduced per-environment
output.targetvalidation ininitConfigs.ts. - Stripped ANSI control characters from caught build errors in shared E2E scripts.
- Added a new E2E case for invalid
output.target.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/core/src/provider/initConfigs.ts | Refactor config.environments guard and add output.target validation |
| e2e/scripts/shared.ts | Import and apply stripVTControlCharacters to sanitize error messages |
| e2e/cases/output/invalid-target/exports-presence/src/index.js | Add placeholder entry point for invalid-target test |
| e2e/cases/output/invalid-target/exports-presence/index.test.ts | Add Playwright test for invalid output.target error |
Comments suppressed due to low confidence (4)
e2e/cases/output/invalid-target/exports-presence/index.test.ts:4
- [nitpick] The test name references an "exportsPresence" error but is actually validating an invalid
output.target. Rename it to something likeshould throw for invalid output.targetfor clarity.
test('should throw error by default (exportsPresence error)', async () => {
e2e/cases/output/invalid-target/exports-presence/index.test.ts:16
- Consider adding a complementary test case that uses valid targets (
web,node,web-worker) to ensure no error is thrown when the value is correct.
expect(rsbuild.buildError?.message).toContain(
packages/core/src/provider/initConfigs.ts:184
- If
output.targetcan also be provided at the top level (outsideenvironments), this early return will skip its validation. Consider validatingconfig.output?.targetbefore returning or clearly documenting that root-level targets must go underenvironments.
if (!config.environments) {
packages/core/src/provider/initConfigs.ts:199
- Directly accessing
outputwithout checking for its existence may throw if an environment has nooutputblock. Add a guard (e.g.const outputConfig = config.environments[name].output || {};) or use optional chaining.
const outputConfig = config.environments[name].output;
There was a problem hiding this comment.
Bug: Undefined `outputConfig` Causes Target Access Error
The validateRsbuildConfig function attempts to access outputConfig.target without ensuring outputConfig is defined. If config.environments[name].output is missing or undefined, this results in a TypeError "Cannot read property 'target' of undefined".
packages/core/src/provider/initConfigs.ts#L199-L201
rsbuild/packages/core/src/provider/initConfigs.ts
Lines 199 to 201 in 55eb005
Was this report helpful? Give feedback by reacting with 👍 or 👎

Summary
Validate the
output.targetin the Rsbuild config to detect configuration errors at an earlier stage.Checklist