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 trialAJ Keith
10,204 PointsTypeError: Class constructor Movie cannot be invoked without 'new' at Object.<anonymous>
When running via 'npm start' script, the terminal returns "TypeError: Class constructor Movie cannot be invoked without 'new' at Object.<anonymous>".
The error flags the line of code where the async function is run. I have tried replacing the init function with sequelize.define but I am getting the same result.
1 Answer
Brian Wright
6,770 PointsI had this problem and was pulling my hair out trying to resolve it. After creating a test folder to resolve the problem I manage to run the exact same code with no issues. The problem I found in my original code is that when I tried to run Movie.sync() or sequelize.sync() inside the IIFE I got the error. After running sync() outside the IIFE or moving Movie.init() inside the IIFE everything was OK. Here is my code:
const sync = async () => { try { await sequelize.sync({ force: true }) } catch (err) { console.error(err.message); } }
sync();
jpizzle
36,395 Pointsjpizzle
36,395 Pointscan you share your code?