SyntaxError: Unexpected token

syntaxerror: unexpected token typescript
syntaxerror: unexpected token spread operator
syntaxerror: unexpected token react
syntaxerror: unexpected token node js
syntaxerror: unexpected token import
syntaxerror: unexpected token jest
syntaxerror: unexpected token three dots
unexpected token < html

No changes made to lang.js file since months ago but suddenly syntax error when trying to preview locally and can't deploy changes.

Not sure why this is happening - could somebody please kindly help? Many thanks!

Disclosure/warning: I have 0 programming knowledge.

MacBook:pty-bus Ying$ node index.js
/Users/Ying/Desktop/pty-bus/lang.js:19
    ...req.lang.marketing.global,
    ^^^
SyntaxError: Unexpected token ...
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/Ying/Desktop/pty-bus/index.js:20:36)
    at Module._compile (module.js:571:32)

lang.js

var path = require('path');

function langMiddleware(req, res, next){
  let lang = req.query.lang || 'en';

  if(['es', 'en'].indexOf(lang) == -1) lang = 'en'

  fs.readFile(path.join(__dirname, 'lang', lang + '.json'), 'utf8', function(err, data){
    req.lang = JSON.parse(data);
    req.langCode = lang;
    next();
  })
};


function render(req, res, template, vars={}){
  let renderObj = {
    ...req.lang.marketing.global,
    title: req.lang.titles[template],
    site_title: req.lang.site_title,
    site_description: req.lang.site_description,
    ...(req.lang.marketing[template] || {}),
    lang: {...(req.lang.marketing.global.language || {})},
    langCode: req.langCode,
    ...vars,
    path: req.path
  };

  res.render(template, renderObj);
}

module.exports = { langMiddleware, render }

It looks like your ability to use spread operator has been removed. I would guess you have recently changed your node version, or edited either your babelrc or webpack config. Either way, I don't think it's anything wrong with your current code in that file.

SyntaxError: Unexpected token, The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. Uncaught SyntaxError: Unexpected token Aug 24 2016Ibrahim Diallo This is a common error in JavaScript, and it is hard to understand at first why it happens. But if you bear with me and remember that Bugs are a good thingyou will be on your way in no time.

Node.js v7.4.0 has V8 5.4 which supports ...operator for arrays, but not for objects. You need at least V8 6.0, i.e. the last Node.js 8 branch version will do (v8.15.0).

JavaScript Error Handling: Unexpected Token, Unexpected Token errors are a subset of SyntaxErrors and, thus, will only appear when attempting to execute code that has an extra (or missing)  SyntaxError: Unexpected token; SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead; SyntaxError: a declaration in the head of a for-of loop can't have an initializer; SyntaxError: applying the 'delete' operator to an unqualified name is deprecated

Tt looks like node v7.4.0 not support spread operator - change let renderObj = {...} to

let renderObj = {
    title: req.lang.titles[template],
    site_title: req.lang.site_title,
    site_description: req.lang.site_description,
    langCode: req.langCode,
    path: req.path
  };

Object.assign(renderObj,
  req.lang.marketing.global,
  (req.lang.marketing[template] || {}),
  vars
);  
renderObj.lang = Object.assign({}, (req.lang.marketing.global.language || {}));

Uncaught SyntaxError: Unexpected token < - JavaScript, Uncaught SyntaxError: Unexpected token <. Aug 24 2016 Ibrahim Diallo. This is a common error in JavaScript, and it is hard to understand at first why it happens​  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

“Uncaught SyntaxError: Unexpected token , The error Uncaught SyntaxError: Unexpected token < is most commonly caused by your site's code referring to an asset that is no longer  SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at Q (angular.js:1333) at Ot (angular.js:10635) at angular.js:10726 at r (angular.js

`Uncaught SyntaxError: Unexpected token !` with `new Method , `Uncaught SyntaxError: Unexpected token !` with `new Method` usage #8762. Closed. extempl opened this issue on Feb 8, 2019 · 5 comments. Closed  “Uncaught SyntaxError: Unexpected token H in JSON” I've recently picked up a project I was working on a bit ago, and when doing an ajax request, after it submits

Uncaught SyntaxError: Unexpected token ) · Issue #1237 · perkeep , Whether I use the 0.10 release or git clone master, I get errors like this in the DOM: Uncaught SyntaxError: Unexpected token ) index.js:641  Unexpected Token errors are a subset of SyntaxErrors and, thus, will only appear when attempting to execute code that has an extra (or missing) character in the syntax, different from what JavaScript expects.

Comments
  • What version of node are you using? (type node --version)
  • You lost me at I have 0 programming knowledge.
  • @Quentin v7.4.0
  • @Quentin Just checked, node version is correct. Just finding it really strange since I haven't touched that file in months and all my other commits and deployments have worked fine.
  • See node.green — Node.js has supported spread syntax, without a flah, since at least 5.12.
  • @Quentin - nope you are wrong - i check on version 6.3.1 and "..." doesnt work - jdoodle.com/execute-nodejs-online
  • In 7.4.0, ... works for arrays, but not for objects.