Skip to content

Commit 27f8331

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular/build): avoid pre-transform errors with Vite pre-bundling
Vite 6.0 change the option location of the `preTransformRequests` to the `dev` section of the Vite configuration. While the previous `server` section option of the same name is still present, it currently does not change behavior when configured. (cherry picked from commit 5c13601)
1 parent 58c2122 commit 27f8331

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

packages/angular/build/src/builders/dev-server/tests/behavior/build-external-dependencies_spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,21 @@ describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupT
8383
expect(text).toContain(`import { BehaviorSubject } from "rxjs";`);
8484
expect(text).toContain(`import { map } from "rxjs/operators";`);
8585
});
86+
87+
// TODO: Enable when Vite has a custom logger setup to redirect logging into the builder system
88+
xit('does not show pre-transform errors in the console for external dependencies', async () => {
89+
harness.useTarget('serve', {
90+
...BASE_OPTIONS,
91+
});
92+
93+
const { result, logs } = await executeOnceAndFetch(harness, 'main.js');
94+
95+
expect(result?.success).toBeTrue();
96+
expect(logs).not.toContain(
97+
jasmine.objectContaining({
98+
message: jasmine.stringMatching('Pre-transform error'),
99+
}),
100+
);
101+
});
86102
});
87103
});

packages/angular/build/src/builders/dev-server/vite-server.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,15 @@ export async function setupServer(
803803
mainFields: ['es2020', 'browser', 'module', 'main'],
804804
preserveSymlinks,
805805
},
806+
dev: {
807+
// This is needed when `externalDependencies` is used to prevent Vite load errors.
808+
// NOTE: If Vite adds direct support for externals, this can be removed.
809+
// NOTE: Vite breaks the resolution of browser modules in SSR
810+
// when accessing a url with two or more segments (e.g., 'foo/bar'),
811+
// as they are not re-based from the base href.
812+
preTransformRequests:
813+
externalMetadata.explicitBrowser.length === 0 && ssrMode === ServerSsrMode.NoSsr,
814+
},
806815
server: {
807816
warmup: {
808817
ssrFiles,
@@ -841,13 +850,6 @@ export async function setupServer(
841850
...[...assets.values()].map(({ source }) => source),
842851
],
843852
},
844-
// This is needed when `externalDependencies` is used to prevent Vite load errors.
845-
// NOTE: If Vite adds direct support for externals, this can be removed.
846-
// NOTE: Vite breaks the resolution of browser modules in SSR
847-
// when accessing a url with two or more segments (e.g., 'foo/bar'),
848-
// as they are not re-based from the base href.
849-
preTransformRequests:
850-
externalMetadata.explicitBrowser.length === 0 && ssrMode === ServerSsrMode.NoSsr,
851853
},
852854
ssr: {
853855
// Note: `true` and `/.*/` have different sematics. When true, the `external` option is ignored.

0 commit comments

Comments
 (0)