Issue
The following error is presented upon starting your application with the v5 Node agent:
for (const svcName of installOrder ?? []) {
^
SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/contrast/agent/node_modules/@contrast/agent/lib/index.js:27:18)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
Cause
The nullish coalescing (??) operator is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand. The nullish coalescing operator works with Node.js >= 14, and the Contrast v5 Node agent supports Node.js LTS versions 16, 18, and 20.
Resolution
There are two solutions to remediate this issue:
- Upgrade the Node.js version for your project. We recommend upgrading the Node.js version for your project in accordance with best practices. Utilizing the active LTS versions of Node.js is advised to mitigate potential security vulnerabilities.
- Use the legacy v4 Node agent
Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing