Skip to content

Instantly share code, notes, and snippets.

@elawad
Last active March 8, 2023 13:42
Show Gist options
  • Save elawad/c0af86ea37629ad0538c2b974b4ea0c1 to your computer and use it in GitHub Desktop.
Save elawad/c0af86ea37629ad0538c2b974b4ea0c1 to your computer and use it in GitHub Desktop.
Sequelize using ES Module imports
require('@babel/register')({
presets: [
['@babel/preset-env', { targets: { node: 'current' } }]
]
});
const path = require('path');
const DB_PATH = 'dist/db'; // use dist instead of src directory
module.exports = {
'config': path.resolve(DB_PATH, 'config.json'),
'models-path': path.resolve(DB_PATH, 'models'),
'seeders-path': path.resolve(DB_PATH, 'seeders'),
'migrations-path': path.resolve(DB_PATH, 'migrations')
};
{
"type": "module",
"engines": {
"node": ">=14.18",
"yarn": ">=1.22"
},
"scripts": {
"start": "node --experimental-specifier-resolution=node src",
"db": "sequelize db:migrate && sequelize db:seed:all",
"predb": "yarn dist",
"dist": "cp -r src dist",
"predist": "rm -rf dist",
"postdist": "node setup-dist.js"
},
"dependencies": {
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.0",
"@babel/register": "^7.16.0",
"sequelize": "^6.8.0",
"sequelize-cli": "^6.2.0"
}
}
import { writeFileSync } from 'fs';
const file = './dist/package.json';
const data = '{ "type": "" }'; // to override ESM in main package.json
writeFileSync(file, data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment