Repository navigation
Closed
Labels
type: featureDEPRECATED: replace with the "feature" issue type
Description
We've enabled AWS X-Ray SDK in our project to benchmark and trace SQL calls.
It requires this:
var AWSXRay = require('aws-xray-sdk');
var mysql = AWSXRay.captureMySQL(require('mysql2'));So you do have sequelize.config.dialectModulePath for a custom (wrapped) mysql2 instance but it is fully dynamic:
if (sequelize.config.dialectModulePath) {
require(sequelize.config.dialectModulePath)
}It won't work in Webpack because Webpack won't bundle anything for such require and will only throw "Module not found: mysql2".
Now, we've worked around it in a hacky way by using string-replace-loader which is set up to patch the library:
const sequelizeMySQLDialectStuffPath = path.resolve(basePath, 'node_modules/sequelize/lib/dialects/mysql/connection-manager.js');
if (!fs.existsSync(sequelizeMySQLDialectStuffPath)) {
throw new Error(`[build error] Sequelize MySQL dialect file not found: ${sequelizeMySQLDialectStuffPath}`);
}
const sequelizeMySQLDialectStuff = fs.readFileSync(sequelizeMySQLDialectStuffPath, 'utf-8');
const sequelizeMySQLDialectStuffRequire = 'require(sequelize.config.dialectModulePath)';
if (sequelizeMySQLDialectStuff.indexOf(sequelizeMySQLDialectStuffRequire) < 0) {
throw new Error(`[build error] Sequelize MySQL dialect file doesn't match.`);
}
{
test: /\.js$/,
include: sequelizeMySQLDialectStuffPath,
use: [{
loader: 'string-replace-loader',
options: {
search: sequelizeMySQLDialectStuffRequire,
replace: `require("${path.resolve(basePath, '/mysql2-wrapped-with-aws-xray.js').replace(/\\/g, '\\\\')}")`,
}
}]
}So as you can see it's hacky and a bit fragile.
You could support something like this instead:
if (sequelize.config.dialectModulePath) {
require(sequelize.config.dialectModulePath)
} else if (sequelize.config.dialectModule) {
// use the `sequelize.config.dialectModule` directly.
}And the config would be:
{
options: {
dialectModule: require('path/to/custom/dialect.js')
}
}Reacted by Yves M., Cyril Bonnet, Jacob Zak, Nicolas Buecher, Lionel - Vousk-prod., Gautier Rollin and Pedro Augusto de Paula Barbosa
Metadata
Metadata
Assignees
Labels
type: featureDEPRECATED: replace with the "feature" issue type
Activity
sushantdhiman commentedon Jun 28, 2018
Will accept PR
catamphetamine commentedon Jun 28, 2018
@sushantdhiman Created a PR: #9609
yvele commentedon Aug 29, 2018
Why not passing directly the module with a new option
sequelize.config.dialectModule? 🤔Then instead of requiring the module it self, Sequelize will also be able to directly use the module.
I'm also struggling setting Sequelize with Webpack (and AWS X-Ray)
Edit: Oops that EXACTLY what @catamphetamine is proposing 😄
sushantdhiman commentedon Aug 29, 2018
Anyone want this feature can takeover #9609 and complete tests #9609 (comment) , I'll merge it
sallyzoughaib commentedon Dec 1, 2023
@catamphetamine @pellejacobs @sushantdhiman @jonmagic @sushantdhiman I am minifying and bundling a Node.js TypeScript backend project that uses Sequelize to connect with a database. I used Webpack for this task and successfully generated the 'bundle.js' file. However, when I ran 'node dist/bundle.js,' the server started, but any request requiring a database connection resulted in an error. After debugging and investigating, I discovered that I am missing Sequelize configurations in my 'web.config.js' file. Could you please help me identify what's missing?
this is my webpack.config.js: