Skip to content

Commit f9d48c2

Browse files
committed
fix(@angular/build): allow serving node_modules assets in monorepo setups
In monorepo setups where node_modules are hoisted to a parent directory above the Angular workspace root, assets loaded from those packages (e.g., fonts from CSS files) were blocked by Vite's dev server with a 403 error. This was caused by the explicit `server.fs.allow` configuration only including the workspace root's `node_modules`, which overrides Vite's default package root detection. By adding `searchForPackageRoot()` to the allow list, the monorepo root directory is included, allowing access to hoisted node_modules. Fixes angular#31016
1 parent 7fbc715 commit f9d48c2

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

  • packages/angular/build/src/builders/dev-server/vite

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { readFile } from 'node:fs/promises';
1010
import { join } from 'node:path';
11-
import type { Connect, InlineConfig, SSROptions, ServerOptions } from 'vite';
11+
import { type Connect, type InlineConfig, type SSROptions, type ServerOptions, searchForPackageRoot } from 'vite';
1212
import type { ComponentStyleRecord } from '../../../tools/vite/middlewares';
1313
import {
1414
ServerSsrMode,
@@ -75,9 +75,12 @@ async function createServerConfig(
7575
// The first two are required for Vite to function in prebundling mode (the default) and to load
7676
// the Vite client-side code for browser reloading. These would be available by default but when
7777
// the `allow` option is explicitly configured, they must be included manually.
78+
// The package root search handles monorepo setups where node_modules may be hoisted
79+
// to a parent directory above the Angular workspace root.
7880
allow: [
7981
cacheDir,
8082
join(serverOptions.workspaceRoot, 'node_modules'),
83+
searchForPackageRoot(serverOptions.workspaceRoot),
8184
...[...assets.values()].map(({ source }) => source),
8285
],
8386
},

0 commit comments

Comments
 (0)