So anyone using sequelize module in their projects and when trying to run your project you we faced with this error as the project was booting up.
This error does not occur only when you have sequelize, it occurs for anyone using modules that use modern ES6 while your project is based on commonJS. e.g the UUID node module
export { default as v1 } from './v1.js';
^^^^^^
SyntaxError: Unexpected token 'export'
Here is a solution that might help, Just a point to note:
I experienced this error when i was deploying my app to digital ocean, i had the latest nodejs version v14.
In your project root directory
install babel and babel development dependencies
npm install --save-dev @babel/core @babel/cli @babel/preset-env @babel/node
this module helps you run modern es6 modules alongside commonJs code
after installing babel
create a .babelrc file in the root directory and add the following code
{
"presets": [
"@babel/preset-env"
]
}
This file when executed will tell babel how to compile ES6 modules found inside the node modules you have installed
The final step is to execute the .babelrc in the node start execution pipeline file.
Open package.json and edit your start script as below
"start" : "node --exec babel-node index.js"
or if using nodemon
"start" : "nodemon --exec babel-node index.js"
Make sure your .babelrc is created at the root directory where package.json, package.lock.json are created by npm init.