I'm facing an issue while developing an Angular application that utilizes xml2js. The error message I encountered is as follows:
$ ng build
⠦ Building...
✘ [ERROR] Could not resolve "timers"
node_modules/xml2js/lib/parser.js:36:25:
36 │ setImmediate = require('timers').setImmediate;
╵ ~~~~~~~~
The package "timers" cannot be found on the file system, but it's inherent in node. Are you attempting to bundle for node? You can use "platform: 'node'" to avoid this error.
Previously, I had no issues building the app, but recently this problem started occurring. I haven't made any changes to angular.json
or tsconfig.app.json
since then. Interestingly, the app functions correctly when running the dev-server using ng serve
and ng serve -c production
.
angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"<NDA_OMIT>": {
"projectType": "application",
...
}
},
"cli": {
"schematicCollections": [
"@angular-eslint/schematics"
]
}
}
tsconfig.app.json
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
...
},
"files": [
"src/main.ts"
],
"include": [
"src/**/*.d.ts"
]
}
ng version
output
Angular CLI: 17.2.0
Node: 20.11.0
Package Manager: npm 10.4.0
OS: linux x64
Angular: 17.2.1
...
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.1702.0
@angular-devkit/build-angular 17.2.0
@angular-devkit/core 17.2.0
@angular-devkit/schematics 17.2.0
...