2

I'm attempting to use optional chaining in my v14.17.5 NodeJS server, but get the following error whenever I use it:

/app/node_modules/babel-core/lib/transformation/file/index.js:558
      throw err;
      ^
SyntaxError: /app/src/schema/index.js: Unexpected token (64:30)
  62 |       return response;
  63 |     } catch (error) {
> 64 |       const errCode = error?.response.error.errCode === 'CannotFind' ? 404 : 500;
     |                               ^

It looks like there's an issue with the babel-core dependency, but I don't have that dependency installed, so I'm not sure what to do. I have the following babel packages installed:

"@babel/helper-hoist-variables": "^7.14.5",
"babel-cli": "6.23.0",
"babel-eslint": "10.1.0",
"babel-plugin-transform-async-to-module-method": "6.22.0",
"babel-plugin-transform-es2015-modules-commonjs": "6.23.0",
"babel-plugin-transform-flow-strip-types": "6.22.0",
"babel-plugin-transform-object-rest-spread": "6.23.0",
"babel-preset-latest": "6.22.0",
"eslint-plugin-babel": "4.0.1",

My start script is the following:

scripts {
 "start": "nodemon ./src/index.js --exec babel-node --watch ./src |       
  bunyan",
}

PS - I'm unsure what babel-node is doing here. If I could remove it some how that'd be awesome.

Noob
  • 754
  • 3
  • 10
  • 27
  • Do you know why Babel is in this project? – Joe Oct 06 '21 at 02:45
  • @Joe I don’t know. I recently inherited this project and I’m not too familiar with using babel with nodemon. It’s an express app. – Noob Oct 06 '21 at 02:50
  • You might need an additional plugin - https://stackoverflow.com/a/61184262/57135 – Joe Oct 06 '21 at 02:57
  • @Joe Awesome. Do you know if it'd be possible to remove babel? Do you know why it's used? I haven't used an express app with babel before - unsure why this would need one (it's over 4 years old) – Noob Oct 06 '21 at 02:58
  • Does this answer your question? [Optional chaining not working in Node 14 LTS?](https://stackoverflow.com/questions/68948480/optional-chaining-not-working-in-node-14-lts) – baruchiro Aug 25 '22 at 12:29

0 Answers0