Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introducing ES2015 Classes Structure of Class

Why is the same code throwing syntax errors in terminal /Mac ?

Running the same code in terminal, throws the following errors: constructor({ name, age, interestLevel = 5 } = {}) { ^

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 Function.Module.runMain (module.js:441:10) at startup (node.js:139:18) at node.js:974:3

Is there anything wrong with my version of node (4.6.1)? Will these lessons become more useful when I get to use a framework ?

1 Answer

andren
andren
28,558 Points

The error is likely caused by the version of node you are using. Node did not get full support (well 99% support) for ES2015 until version 6.

You can see a list of ES2015 features that various versions of Node supports on this page. According to that page version 4 only supported about 57% of the ES2015 feature set, and destructuring is one of the features not supported at all.

So you should upgrade to at least the newest LTS release (Version 6.11.1) if you plan on using ES2015 features.