sequelize / cli

The Sequelize CLI
MIT License
2.53k stars 528 forks source link

ERROR: Error reading "src/core/database/config.ts". #1099

Open halilbaydar opened 2 years ago

halilbaydar commented 2 years ago

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]

Falinor commented 2 years ago

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.

cyrilchapon commented 2 years ago

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 sequelize-cli@6.2.0; 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'
  ),
  // [...]
}
TarasMakarchuk commented 1 year ago

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.

ArturBarilo commented 1 year ago

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

TarasMakarchuk commented 1 year ago

Alternatively, you can try typing npm uninstall sequelize/cli, then write manually npm i sequelize-cli@6.3.0

https://www.npmjs.com/package/sequelize-cli/v/6.3.0

ArturBarilo commented 1 year ago

Thanks a lot It's works

Adhiana46 commented 1 year ago

Alternatively, you can try typing npm uninstall sequelize/cli, then write manually npm i sequelize-cli@6.3.0

https://www.npmjs.com/package/sequelize-cli/v/6.3.0

thank you it work for me

sireaev commented 11 months ago

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

alvincrisuy commented 10 months ago

Hi still not being solved?

ArturBarilo commented 10 months ago

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: @.***>

alvincrisuy commented 10 months ago

What I mean is without downgrading?

alvincrisuy commented 7 months ago

At this moment this still exist.

MichaelPote commented 7 months ago

Also just ran into this issue today. Still unfixed as of CLI 6.6.2

alvincrisuy commented 7 months ago

how come you closed this ticket @halilbaydar ?

falk-stefan commented 6 months ago

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 sequelize-cli@6.3.0, 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
vincentdesmares commented 6 months ago

Can confirm that I also had to downgrade to 6.3.0

zohaibamir203 commented 5 months ago

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 sequelize-cli@6.3.0, 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 ?

falk-stefan commented 5 months ago

@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'),
};
moeldeeb1998 commented 5 months ago

it works properly with just js files so you have to change config file extenstion to be config.js