Reputation: 121
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
Upvotes: 10
Views: 5579
Reputation: 2541
It's maybe quite late to give the solution, but I struggled with this issue and none of the previous solutions worked for me. The problem is that Node triggers Sequelize without reading the code transformed by Babel.
To do so, just fix the scripts in the following way. I donc use "type": "module"
in the package.json. I prefer to use Babel, to trigger the server too.
"scripts": {
"build": "babel src -d dist",
"dev": "nodemon --exec babel-node ./src/index.js",
"start": "yarn run build && node dist/index.js",
"test": "nyc --reporter=text mocha --config=test/.mocharc.json",
"test:watch": "mocha --config=test/.mocharc.json -- --watch",
"sequelize": "babel-node node_modules/.bin/sequelize $*",
"db:drop": "dropdb --if-exists ${POSTGRES_DB}",
"db:create": "createdb ${POSTGRES_DB}",
"db:migrate": "yarn sequelize db:migrate",
"db:rollback": "yarn sequelize db:migrate:undo"
},
The script sequelize
reads node_modules/.bin/sequelize $*
throught babel-node
Upvotes: 0
Reputation: 1143
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.
Upvotes: 1
Reputation: 2885
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.
Upvotes: 4