Reputation: 4608
I have this .sequelizerc file:
const path = require('path');
module.exports = {
config: path.resolve('.', 'src/config/sequelizeCLIConfig.json'),
'migrations-path': path.resolve('.', 'db', 'migrations'),
};
And then I have a .ts file that generates the cli config file named generateSequelizeCLIConfig.ts
, which does the following thing:
import path from 'path';
import fs from 'fs';
import config from '../../src/config';
import sequelizeRC from '../../.sequelizerc';
const env = process.env.NODE_ENV || 'development';
const targetFile = path.resolve(sequelizeRC.config);
const sequelizeCLIConfig: Record<string, any> = {};
sequelizeCLIConfig[env] = config.db;
fs.writeFile(targetFile, JSON.stringify(sequelizeCLIConfig, null, 4), err => {
if (err) {
return console.log(err);
}
console.log('The sequelizeCLI config file was saved at ' + targetFile + '!');
});
The plan is, every time I need migration, I run this script first. This script grabs the data from the config folder and generate the src/config/sequelizeCLIConfig.json
. And then I run the migration with config data from this .json file.
So the file structure is this:
-.sequelizerc
-db
|-scripts
|-generateSequelizeCLIConfig.ts
-src
|-config
|-index.ts
.sequelizerc
However I got this error when compiling generateSequelizeCLIConfig.ts
:
TSError: ⨯ Unable to compile TypeScript:
db/scripts/generateSequelizeCLIConfig.ts(4,25): error TS2307: Cannot find module '../../.sequelizerc'.
So it seems .sequrlizerc is not recognized although I have double checked that this file does exist.
My guess is, .sequelizerc behind the scene is a .js file, not a .ts file, and this gives me some trouble. But I don't know how to verify this, nor how to fix it.
Any suggestions?
Upvotes: 1
Views: 7318
Reputation: 1102
Try to add the .sequelizerc
to your include in your tsconfig
as follows:
{
..prev configs...,
include: [ ...your paths..., ".sequelizerc"],
}
Upvotes: 6