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 Using SQL ORMs with Node.js Performing CRUD Operations Attributes, Operators and Ordering

Class constructor Sequelize cannot be invoked without 'new'

Returning the following error when trying to extract the Op property from db.Sequelize

 const { Op } = db.Sequelize
              ^

 TypeError: Class constructor Sequelize cannot be invoked without 'new'

2 Answers

James Crosslin
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James Crosslin
Full Stack JavaScript Techdegree Graduate 16,882 Points

Obviously I'm really late here, but there's no semicolon after this statement. If you're in app.js, the very next bit of code is an IIFE which starts with an opening parenthesis. Without a semicolon to indicate that the line is completed and the IIFE is a new and unrelated expression, the JS interpreter believes that you're trying instantiate Sequelize as it removes the white space and places that opening parenthesis directly after db.Sequelize.

As you increasingly begin lines with data structures or expressions that the Javascript interpreter cannot differentiate as a new line, you will need to manually (your formatters are not likely to catch this either) insert semicolons. They are not optional in these cases. I would suggest always finishing your lines with semicolons.

Hi James.

My understanding is that the newer version of Javascript removed the requirement to end every line with semicolon. I don't like how they did that. Wish it would require the semicolon just to keep it all consistent. Now I have some lines with semicolon and some without, just because the compiler doesn't flag a syntax error.

James Crosslin
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James Crosslin
Full Stack JavaScript Techdegree Graduate 16,882 Points

Hey Jason,

It is true that JavaScript does not require a semicolon at the end of a line…with the critical exception of when the following expression beings with an anonymous data structure like an IIFE or array brackets or object braces.

I agree that this was a bad move. You can set an eslint config (or prettier et al) to format your files and insert semicolons. It may goof things up in situations like this, but it’s usually pretty obvious if you’re formatting often.