I'm trying to run Sequelize and is giving the following export error in the UUID module:
File: /uuid/dist/esm-browser/index.js:1
export { default as v1 } from './v1.js';
^^^^^^
SyntaxError: Unexpected token 'export'
What is the right way to solve this? I'm using node
To solve the "Uncaught SyntaxError Unexpected token 'export'", refactor your code to use the CommonJS syntax, e.g. module. exports = {num}; instead of export num = 10; . Copied!
Uncaught SyntaxError Unexpected token 'export'# The "Uncaught SyntaxError Unexpected token 'export'" error occurs for 2 main reasons: Using the ES6 Module syntax in a Node.js application without typeto modulein package.json.
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 Here is a solution that might help, Just a point to note:
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
Nope. UUID is distributed as commonjs by default. How do you import uuid? And provide please minimal reproduction. Sorry, something went wrong. which pointed to this file: What am i missing here? what is the root of problem ? uuidv4? uuid? esm-browser???? Sorry, something went wrong. Show how do you import uuid, give us a reproduction.
This is a problem in the https://github.com/uuidjs/uuid/ package where they don't support odd Node versions https://github.com/uuidjs/uuid/issues/466 .
Upgrade your Node version. I'm now on 14.4.0 and it works fine.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With