Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
halilbaydar opened this issue May 29, 2022 · 19 comments
Open

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

halilbaydar opened this issue May 29, 2022 · 19 comments

Comments

@halilbaydar
Copy link

halilbaydar commented May 29, 2022

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
Copy link

Falinor commented Jun 12, 2022

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
Copy link

cyrilchapon commented Sep 5, 2022

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
Copy link

TarasMakarchuk commented Oct 27, 2022

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
Copy link

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
Copy link

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
Copy link

ArturBarilo commented May 25, 2023

Thanks a lot
It's works

@Adhiana46
Copy link

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
Copy link

sireaev commented Oct 2, 2023

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
Copy link

Hi still not being solved?

@ArturBarilo
Copy link

ArturBarilo commented Nov 5, 2023 via email

@alvincrisuy
Copy link

What I mean is without downgrading?

TheEgghead27 added a commit to stuysu/opportunities-api.stuysu.org that referenced this issue Feb 5, 2024
See sequelize/cli#1099 "closed as completed"
my rear end...
@alvincrisuy
Copy link

At this moment this still exist.

@MichaelPote
Copy link

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

@alvincrisuy
Copy link

how come you closed this ticket @halilbaydar ?

@falk-stefan
Copy link

falk-stefan commented Feb 17, 2024

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

@halilbaydar halilbaydar reopened this Feb 17, 2024
@vincentdesmares
Copy link

Can confirm that I also had to downgrade to 6.3.0

@zohaibamir203
Copy link

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
Copy link

falk-stefan commented Mar 30, 2024

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests