Around 10:30 PST today Sept 10 2024 my ng build command suddenly started giving this error on ng build. Yes I know I’m on an old build and I recognize the answer probably is “Upgrade everything to the latest,” but if there is another answer that’d be cool.
Unexpected token {
/Users/[email protected]/git/provider-fee-ui/node_modules/pump/index.js:7
} catch {}
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/[email protected]/git/provider-fee-ui/node_modules/mississippi/index.js:1:85)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
ng v
_ _ ____ _ ___
/ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ | '_ / _` | | | | |/ _` | '__| | | | | | |
/ ___ | | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ __| |_|__, |__,_|_|__,_|_| ____|_____|___|
|___/
Angular CLI: 7.0.7
Node: 8.9.0
OS: darwin x64
Angular: 7.2.16
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.13.10
@angular-devkit/build-angular 0.13.10
@angular-devkit/build-optimizer 0.13.10
@angular-devkit/build-webpack 0.13.10
@angular-devkit/core 7.3.10
@angular-devkit/schematics 7.0.7
@angular/cdk 7.3.7
@angular/cli 7.0.7
@angular/flex-layout 7.0.0-beta.24
@angular/material 7.3.7
@ngtools/webpack 7.3.10
@schematics/angular 7.0.7
@schematics/update 0.10.7
rxjs 5.6.0-forward-compat.5
typescript 3.1.8
webpack 4.29.0
node -v
v8.9.0
npm -v
5.5.1
1
Answering my own question –
Looks like pump 3.0.1 is not compatible with Angular 7. I performed a
npm install [email protected]
Which put the following in my package.json
“pump”: “^3.0.0”,
Which I then had to modify to
“pump”: “3.0.0”,
and then the compile error went away on my ng build
Don’t know if it is because of Angular 7 but pump 3.0.1 makes a try catch without using an error parameter:
try {
fs = require('fs') // we only need fs to get the ReadStream and WriteStream prototypes
} catch {}
This is supported starting with JS specification ECMAScript 2019/ES10.
So this might be the problem behind.