Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng command giving error, SyntaxError: Unexpected token ). centos 7

I faced an issue on the centOs7 server while checking the version of angular-cli by ng -v. I got the output as below:

/usr/lib/node_modules/@angular/cli/bin/ng:23
  );
  ^
SyntaxError: Unexpected token )
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.runMain (module.js:611:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:160:9)

Even not able to build the project because of this issue, I am using Jenkins for making build.

like image 894
Mayank Chauhan Avatar asked Apr 14 '26 17:04

Mayank Chauhan


1 Answers

To resolve this issue, I performed the following steps:

  1. sudo vi /usr/lib/node_modules/@angular/cli/bin/ng

  2. find the syntax,

var version = process.versions.node.split('.').map(part => Number(part));
if (version[0] < 10 || version[0] === 11 || (version[0] === 10 && version[1] < 13)) {
  process.stderr.write(
    'Node.js version ' + process.version + ' detected.\n' +
    'The Angular CLI requires a minimum Node.js version of either v10.13 or v12.0.\n\n' +
    'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
  );
}
  1. remove extra comma(,) after \n
  2. save the file and exit

This will resolve the issue. I hope this will help.

like image 171
Mayank Chauhan Avatar answered Apr 17 '26 11:04

Mayank Chauhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!