11

I am a new Bie to node.js. I am getting Syntax Error:

Unexpected token { in my node.js application

I am using v4.5.5 on windows 7 64 bit os.

  const {
        ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)

Let me know how to get rid of this.

Any help would be appreciated.

Thanks

Pradeep

4
  • 1
    Without seeing your code, there's absolutely no way to tell. Commented Aug 9, 2016 at 17:41
  • Why do you have a { after const? Commented Aug 9, 2016 at 17:44
  • 1
    reinstall node nodejs.org/en Commented Feb 15, 2017 at 23:55
  • 6
    Too much hostility and downvotes to a totally legit question here. @MarcB, your link to the "FM" is useless as this way to declare a constant is not present. The synthax is correct, as it's said in the answers, is just a node version issue. So, go FTFM. Commented Mar 2, 2017 at 17:02

3 Answers 3

16

The issue got fixed by upgrading node js to v6.3.1 . After upgrading to 6.3.1 ,I got another error related to isomorphoc-fetch that I fixed it by using npm install --save isomorphic-fetch es6-promise

Ref Link: https://www.npmjs.com/package/isomorphic-fetch.

Thanks all for your inputs

Sign up to request clarification or add additional context in comments.

2 Comments

The node version I am using is 6.11.3, but still, the issue persists. Can anyone please help?
hi Andy can you please raise a separate question since the version what I specified and what you are specifying is different.There might be some changes in 6.11.3.Also mention the issue your facing.
9

From your code const { name, age } = user; seems like you try using object destruction in Node v4 it's available in Node v6.

If it's not possible to switch to v6 you have to refactor the destruct statements into classical object property access(const name = user.name; const age = user.age). Also, you could transpile the code with babel.

Comments

5

You must probably set harmony destructuring flag like, (if you are using less than Node version 6)

node --harmony-destructuring app.js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.