SyntaxError: Unexpected token '.'

On Local working fine but once I am deploying on ec2 server then the given issue coming.

Server wasn’t able to start properly.
[2022-05-02 12:23:15.694] error: Unexpected token ‘.’
/usr/src/app/src/api/ins-total-calc/controllers/ins-total-calc.js:251
calculationsData?.forEach((cd) => {
^

SyntaxError: Unexpected token ‘.’
at compileFunction ()
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 loadFile (/usr/src/app/node_modules/@strapi/strapi/lib/core/loaders/apis.js:153:14)
at loadDir (/usr/src/app/node_modules/@strapi/strapi/lib/core/loaders/apis.js:142:38)
at async Promise.all (index 3)
at async loadAPI (/usr/src/app/node_modules/@strapi/strapi/lib/core/loaders/apis.js:76:7)
at async Object.module.exports [as loadAPIs] (/usr/src/app/node_modules/@strapi/strapi/lib/core/loaders/apis.js:30:19)
at async Strapi.loadAPIs (/usr/src/app/node_modules/@strapi/strapi/lib/Strapi.js:285:5)
at async Promise.all (index 3)
at async Strapi.register (/usr/src/app/node_modules/@strapi/strapi/lib/Strapi.js:309:5)
error Command failed with exit code 1.

This is because you are trying to use optional chaining (?.) with node 12 or lower.

Thats’s not possible.

To use optional chaining you should use node 14 or higher.

1 Like

Hi,
I am using the node 16, still I am getting this error. please help me on this

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 Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
Error: Process completed with exit code 1.
Node version

1 Like

Did you ever solve this? I am having the same issue, maybe due to the build working with a different version. If I don’t use --ignore-engines, I get and error complaining that packages can only find 12.20.1 which is not the live version of node available. So I think they are linked.