Проблема с генерациями миграций typeorm
Уже второй день борюсь с путями для генерации миграций. Пишу yarn migration:generate. Проблема с импортами в ts файлах. Если я меняю с @src/config/.... на ../../config то все прекрасно работает :)
Ошибка
yarn migration:generate
yarn run v1.22.19
$ typeorm-ts-node-commonjs migration:generate -d database/data-source.config.ts database/migrations
Error during migration generation:
Error: Unable to open file: "D:\www\user-service\database\data-source.config.ts". Cannot find module '@src/config/app.config'
Require stack:
- D:\www\user-service\database\data-source.config.ts
- D:\www\user-service\node_modules\typeorm\util\ImportUtils.js
- D:\www\user-service\node_modules\typeorm\commands\CommandUtils.js
- D:\www\user-service\node_modules\typeorm\commands\SchemaSyncCommand.js
- D:\www\user-service\node_modules\typeorm\cli.js
- D:\www\user-service\node_modules\typeorm\cli-ts-node-commonjs.js
at Function.loadDataSource (D:\www\user-service\node_modules\src\commands\CommandUtils.ts:22:19)
at async Object.handler (D:\www\user-service\node_modules\src\commands\MigrationGenerateCommand.ts:73:26)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Package.json
{
"name": "based-project",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"typeorm": "typeorm-ts-node-commonjs",
"migration:create": "typeorm-ts-node-commonjs migration:generate -d database/data-source.config.ts database/migrations",
"migration:generate": "typeorm-ts-node-commonjs migration:generate -d database/data-source.config.ts database/migrations",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"prepare": "husky install"
},
"dependencies": {
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/cqrs": "^9.0.1",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/typeorm": "^9.0.1",
"class-validator": "^0.14.0",
"envalid": "^7.3.1",
"module-alias": "^2.2.2",
"pg": "^8.8.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"typeorm": "^0.3.11",
"uuid": "^9.0.0"
},
"devDependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@types/express": "^4.17.13",
"@types/jest": "29.2.4",
"@types/node": "18.11.18",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^8.0.0",
"jest": "29.3.1",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "29.0.3",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.1",
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "./",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged lint-staged"
}
},
"lint-staged": {
"*.ts": [
"yarn lint:fix"
]
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"_moduleAliases": {
"@src": "./dist"
}
}
tsconfig.json
{ "compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": ".",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"paths": {
"@src": [
"src"
],
"@src/*": [
"./src/*"
]
}, } }