-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
typeorm migration:generate cannot work with entities that import from libraries in the same repo #9122
Comments
I think this could be fixed by specifying what options are passed to ts-node in both https://github.com/typeorm/typeorm/blob/master/src/cli-ts-node-commonjs.ts and https://github.com/typeorm/typeorm/blob/master/src/cli-ts-node-esm.ts |
same problem here |
I've managed to work around this issue in the following manner: #!/usr/bin/env node
import { register } from 'ts-node';
register({ transpileOnly: true, });
import 'typeorm/cli'; and then putting the following in my {
...
"scripts": {
...
"typeorm": "ts-node --project ./tsconfig.base.json -r tsconfig-paths/register ./tools/typeorm.custom-cli.ts"
}
} Then the generate migrations command can be run as follows:
Where import { DataSource } from 'typeorm';
import { SqlServerConnectionOptions } from 'typeorm/driver/sqlserver/SqlServerConnectionOptions';
const config = {
type: 'mssql',
host: 'hostt', // adjust
port: 1433,
username: 'username', // adjust
password: '***snip***', // adjust
database: 'user', // adjust
entities: ['libs/some-project/backend/user/src/lib/domain/**/*.entity.ts'], // adjust
migrations: ['libs/some-project/backend/user/src/lib/infrastructure/migrations/*.ts'], // adjust
synchronize: false,
logging: false,
options: {
encrypt: true,
enableArithAbort: true,
},
migrationsRun: true,
pool: {
max: 100,
min: 0,
idleTimeoutMillis: 30000,
}
} as SqlServerConnectionOptions;
export default new DataSource(config); |
@p-v-d-Veeken The code you provided works! Would you mind explain it for a while ? |
I couldn't make this solution work, @p-v-d-Veeken. I've receiving the error:
Is there anything environment-specific to make this work? Is your sample github that you mentioned when opening the issue updated with the correct solution? Or is it the initial not-working version? My tsconfig.base.json is exactly the same as the one in your github repository. I have node v18.12.1, ts-node v10.9.1 and I'm using nestjs/typeorm v9.0.1 with typeorm v0.3.10. What is your environment? |
same issue here |
1 similar comment
same issue here |
I had the same problem {
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
The problem was solved! So we conclude that typeorm must be able to find the typescript configuration file and most likely tsconfig.json must be in the root of the project and the following options must be active in it: {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
}
|
Issue Description
I have an Nx monorepo with several nestjs libs which each have their own typeorm configuration (i.e. their own database). The entities in these libs all import from a shared utilities library.
Since Typeorm 0.3.x generating migrations for each of these libs is broken due to the typeorm cli not understanding how it needs to handle imports.
Neither of these commands work:
nor:
Expected Behavior
A correctly generated migration.
Actual Behavior
The first command errors with:
The second command errors with:
Steps to Reproduce
My Environment
Additional Context
My project is in an Nx Monorepo (version 14.3.6) and is using @nestjs/typeorm ^8.1.4
Relevant Database Driver(s)
aurora-mysql
aurora-postgres
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
spanner
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: