forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular/build): show error when Node.js built-ins are used durin…
…g `ng serve` This commit ensures consistent behavior between `ng build` and `ng serve`. Previously, `ng serve` did not display an error message when Node.js built-in modules were included in browser bundles. By default, Vite replaces Node.js built-ins with empty modules, which can lead to unexpected runtime issues. This update addresses the problem by surfacing clear error messages, providing better developer feedback and alignment between the two commands. Closes: angular#27425
- Loading branch information
1 parent
75998eb
commit 5186a77
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/legacy-cli/e2e/tests/vite/browser-node-module-dep-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import assert from 'node:assert'; | ||
import { execAndWaitForOutputToMatch, ng } from '../../utils/process'; | ||
import { writeFile } from '../../utils/fs'; | ||
|
||
export default async function () { | ||
await ng('cache', 'clean'); | ||
await ng('cache', 'on'); | ||
|
||
// The `@angular/cli` package relies on Node.js dependencies and is not designed for use in a browser environment. | ||
await writeFile('src/main.ts', `import '@angular/cli';`); | ||
|
||
const { stderr } = await execAndWaitForOutputToMatch('ng', ['serve', '--port=0'], /ERROR/, { | ||
CI: '0', | ||
NO_COLOR: 'true', | ||
}); | ||
|
||
assert.match( | ||
stderr, | ||
/The package "node:util" wasn't found on the file system but is built into node/, | ||
); | ||
} |