cli icon indicating copy to clipboard operation
cli copied to clipboard

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

Open halilbaydar opened this issue 3 years ago • 19 comments

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]

halilbaydar avatar May 29 '22 10:05 halilbaydar

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.

Falinor avatar Jun 12 '22 08:06 Falinor

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'
  ),
  // [...]
}

cyrilchapon avatar Sep 05 '22 12:09 cyrilchapon

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.

TarasMakarchuk avatar Oct 27 '22 10:10 TarasMakarchuk

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

ArturBarilo avatar May 25 '23 19:05 ArturBarilo

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

TarasMakarchuk avatar May 25 '23 20:05 TarasMakarchuk

Thanks a lot It's works

ArturBarilo avatar May 25 '23 20:05 ArturBarilo

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

Adhiana46 avatar Jun 14 '23 03:06 Adhiana46

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

sireaev avatar Oct 02 '23 12:10 sireaev

Hi still not being solved?

alvincrisuy avatar Nov 05 '23 09:11 alvincrisuy

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

ArturBarilo avatar Nov 05 '23 10:11 ArturBarilo

What I mean is without downgrading?

alvincrisuy avatar Nov 06 '23 07:11 alvincrisuy

At this moment this still exist.

alvincrisuy avatar Feb 07 '24 05:02 alvincrisuy

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

MichaelPote avatar Feb 07 '24 13:02 MichaelPote

how come you closed this ticket @halilbaydar ?

alvincrisuy avatar Feb 09 '24 10:02 alvincrisuy

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

falk-stefan avatar Feb 17 '24 14:02 falk-stefan

Can confirm that I also had to downgrade to 6.3.0

vincentdesmares avatar Mar 01 '24 10:03 vincentdesmares

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

I am facing same issue did you find any solution ?

zohaibamir203 avatar Mar 27 '24 05:03 zohaibamir203

@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'),
};

falk-stefan avatar Mar 30 '24 16:03 falk-stefan

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

moeldeeb1998 avatar Apr 06 '24 23:04 moeldeeb1998