-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
Command
serve
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
18.2.11
Description
Hello,
We use node-forge in our Angular app. It is distributed as CommonJS module, and we are aware of the downsides. However, it used to work well in browser, as it has heuristics to learn the environment where the code is executed.
We have switched to new builder as soon as it was released with Angular 17. So it seems the breaking change is introduced in v19.
After migration to Angular v19, it looks like ng serve
tries to execute/analyze the code during build stage and falls into a branch, which is intended for NodeJS environment.
Probably, it is related to server-side rendering optimizations introduced in version 19, which makes development server execute the code.
I would be grateful if there is any workaround to set development server behavior similar to what existed in v18.
Thank you.
Minimal Reproduction
-
Create new project with Angular v19
-
Install typings for node-forge:
npm i @types/node-forge
-
Import and use forge in any component. Example:
// other imports import * as forge from 'node-forge'; @Component({/* ... */}) export class AppComponent { title = 'tmp-ng'; something = forge.util.isArray([]); }
-
ng serve
Exception or Error
X [ERROR] The package "crypto" wasn't found on the file system but is built into node. [plugin angular-browser-node-built-in]
node_modules/node-forge/lib/prng.js:16:20:
16 │ _crypto = require('crypto');
╵ ~~~~~~~~
### and after first request to the Vite server:
Waiting for the debugger to disconnect...
C:\Data\projects\kms-web-ui\node_modules\vite\node_modules\esbuild\lib\main.js:1472
let error = new Error(text);
^
Error: Build failed with 1 error:
node_modules/node-forge/lib/prng.js:16:20: ERROR: [plugin: angular-browser-node-built-in] The package "crypto" wasn't found on the file system but is built into node.
at failureErrorWithLog (C:\Data\projects\kms-web-ui\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15)
at C:\Data\projects\kms-web-ui\node_modules\vite\node_modules\esbuild\lib\main.js:945:25
at C:\Data\projects\kms-web-ui\node_modules\vite\node_modules\esbuild\lib\main.js:1353:9
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
errors: [Getter/Setter],
warnings: [Getter/Setter]
}
Node.js v20.11.1
Your Environment
Angular CLI: 19.0.4
Node: 20.11.1
Package Manager: npm 10.8.1
OS: win32 x64
Angular: 19.0.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1900.4
@angular-devkit/build-angular 19.0.4
@angular-devkit/core 19.0.4 (cli-only)
@angular-devkit/schematics 19.0.4
@angular/cdk 19.0.2
@angular/cli 19.0.4
@angular/material 19.0.2
@schematics/angular 19.0.4
rxjs 7.8.1
typescript 5.5.4
zone.js 0.15.0
Anything else relevant?
The require
line is executed under condition forge.util.isNodejs
:
where