cli
cli copied to clipboard
ERROR: Error reading "src/core/database/config.ts".
ERROR: Error reading "src/core/database/config.ts". Error: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/../src/core/database/config.ts
I'm trying to migrate db with npx sequelize-cli db:migrate command, but it throws the above exception.
My Config File: config.ts
module.exports = { development: { default: { username: process.env.DB_USER, password: process.env.DB_PASS, database: process.env.DB_NAME_GLOBAL, host: process.env.DB_HOST, port: process.env.DB_PORT, dialect: process.env.DB_DIALECT }, transaction: { username: process.env.DB_USER, password: process.env.DB_PASS, database: process.env.DB_NAME_TRANSACTION, host: process.env.DB_HOST, port: process.env.DB_PORT, dialect: process.env.DB_DIALECT } }, };
__Dialect: postgres __Database version: PostgreSQL 14.3 __Sequelize CLI version: Version 4.7.2 __Sequelize version: Sequelize CLI [Node: 14.18.1, CLI: 6.4.1, ORM: 6.20.0]
Hey,
I encountered the same problem. It seems related to the version 6.4.0 as far as I searched. Looks like it's related to the support of ESM modules.
Trying with v6.3.0 allowed me to migrate correctly though.
I commented the merged PR for v6.4.0 there.
Same stuff in here; I historically had these npm scripts :
{
"db:migrate": "yarn sequelize:ts db:migrate",
"sequelize:ts": "ts-node ./node_modules/.bin/sequelize"
}
Working perfectly on [email protected]; but breaking on @6.4.1 with :
ERROR: Error reading "src/database/_config.ts". Error: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for [...]/api/src/database/_config.ts
sequelizerc looks like this :
const path = require('path')
module.exports = {
'config': path.resolve(
'src',
'database',
'_config.ts'
),
// [...]
}
I Faced the same problem on run sequelize migrations Error reading "src\database\config.ts". Error: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" on sequelize/cli 6.5.1. I downgraded it to version 6.3.0 and the migrations worked.
How I can downgrade sequelize/cli version on 6.3.0 with npm? I chande version manually in package.json, in package-lock.json vesrsion changes automatically, but in terminal I saw version 6.6.0
Alternatively, you can try typing npm uninstall sequelize/cli, then write manually npm i [email protected]
https://www.npmjs.com/package/sequelize-cli/v/6.3.0
Thanks a lot It's works
Alternatively, you can try typing npm uninstall sequelize/cli, then write manually npm i [email protected]
https://www.npmjs.com/package/sequelize-cli/v/6.3.0
thank you it work for me
downgrading to 6.3.0 from 6.6.1 helped me too, what is the status of fixing this issue, I think there's something under the hood not supporting typescript files, whether not reading it, who knows? I can contribute to fixing it, just tell me where can I fix it or some details related
Hi still not being solved?
Hi Problem is solved Just downgrade sequelize-cli to v.6.3.0
вс, 5 нояб. 2023 г., 11:54 Alvin Cris Uy @.***>:
Hi still not being solved?
— Reply to this email directly, view it on GitHub https://github.com/sequelize/cli/issues/1099#issuecomment-1793676972, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZIP4NOW7U7VTGMQNK26OMTYC5H6HAVCNFSM5XH7BPO2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZZGM3DONRZG4ZA . You are receiving this because you commented.Message ID: @.***>
What I mean is without downgrading?
At this moment this still exist.
Also just ran into this issue today. Still unfixed as of CLI 6.6.2
how come you closed this ticket @halilbaydar ?
Joining the party
$ sequelize-cli --version
Sequelize CLI [Node: 18.17.0, CLI: 6.6.1, ORM: 6.36.0]
6.6.1
After downgrading npm i -D [email protected], I am not able to run it either as I am getting:
ERROR: Error reading "src/db/config.ts". Error: SyntaxError: Cannot use import statement outside a module
Can confirm that I also had to downgrade to 6.3.0
Joining the party
$ sequelize-cli --version Sequelize CLI [Node: 18.17.0, CLI: 6.6.1, ORM: 6.36.0] 6.6.1After downgrading
npm i -D [email protected], I am not able to run it either as I am getting:ERROR: Error reading "src/db/config.ts". Error: SyntaxError: Cannot use import statement outside a module
I am facing same issue did you find any solution ?
@zohaibamir203 I'm now on 6.6.2 with the following tsconfig.json:
{
"compilerOptions": {
"target": "es2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "./src",
"sourceMap": true,
"outDir": "./dist",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": false,
"skipLibCheck": true,
"allowJs": true,
"checkJs": false,
"experimentalDecorators": true
},
"include": [
"src/**/*.ts",
"src/**/*.js"
],
"exclude": [
"node_modules"
]
}
and in package.json
"type": "module",
"scripts": {
"db:ms": "npm run db:migrate && npm run db:seed",
"db:migrate": "sequelize-cli db:migrate",
"db:seed": "sequelize-cli db:seed:all --debug",
The configuration-file is named config.js (not .ts) but I am able to use TypeScript-import:
// File: db/config.js
import { AuthTypes, Connector, IpAddressTypes } from '@google-cloud/cloud-sql-connector';
import dotenv from 'dotenv';
const config = dotenv.config();
// ...
with .sequelizerc
require("@babel/register")
const path = require('path');
module.exports = {
'config': path.resolve('src', 'db', 'config.js'),
'models-path': path.resolve('src', 'db', 'entity'),
'migrations-path': path.resolve('src', 'db', 'migrations'),
'seeders-path': path.resolve('src', 'db', 'seeders'),
};
it works properly with just js files so you have to change config file extenstion to be config.js