When a custom converter is used on a column, migration fails.(nestjs+typeorm)
Sailiy opened this issue · 1 comments
Sailiy commented
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
Hello, I customized the converter on a column and the migration failed.
timestamp.transformer.ts:
import { ValueTransformer } from 'typeorm';
export class TimestampTransformer implements ValueTransformer {
from(value: Date): number {
return value.getTime(); //Convert to timestamp
}
to(value: number): Date {
return new Date(value); // Converts a timestamp to a date object
}
}
device.dto.ts
import { TimestampTransformer } from 'src/global/transformer/timestamp.transformer';
@Entity()
export class Device {
//.....
@Column({ type: 'datetime', transformer: new TimestampTransformer() })
exptime: number;
}
package.json
"scripts": {
"typeorm": "typeorm-ts-node-esm -d ormconfig.ts",
"migration:generate": "npm run typeorm -- migration:generate ./migrations/test",
}
With transformer removed from the dto column, the migration worked fine. Adding 'transformer: new TimestampTransformer()' causes the following error:
Error during migration generation:
Error: Cannot find module 'src/global/transformer/timestamp.transformer'
Require stack:
- D:\xxx\src\device\entities\device.entity.ts
- D:\xxx\node_modules\typeorm\util\ImportUtils.js
- D:\xxx\node_modules\typeorm\commands\CommandUtils.js
- D:\xxx\node_modules\typeorm\commands\SchemaSyncCommand.js
- D:\xxx\node_modules\typeorm\cli.js
- D:\xxx\node_modules\typeorm\cli-ts-node-esm.js
Minimum reproduction code
null
Steps to reproduce
Refer to the above code
Expected behavior
no error
Package version
9.0.1
NestJS version
9.0.0
Node.js version
16.19.1
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
Dependency | Version |
---|---|
Operating System | windows11 |
Node.js version | 16.19.1 |
Typescript version | 4.7.4 |
TypeORM version | 0.3.15 |
other: |
"dependencies": {
"@nestjs/cache-manager": "^1.0.0",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.3.1",
"@nestjs/core": "^9.0.0",
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/typeorm": "^9.0.1",
"cache-manager": "^5.2.1",
"cache-manager-redis-store": "^3.0.1",
"cache-manager-redis-yet": "^4.1.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"cross-env": "^7.0.3",
"crypto-js": "^4.1.1",
"dotenv": "^16.0.3",
"express-rate-limit": "^6.7.0",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.2.4",
"nodemailer": "^6.9.2",
"redis": "^4.6.6",
"reflect-metadata": "^0.1.13",
"request-ip": "^3.3.0",
"rxjs": "^7.2.0",
"typeorm": "^0.3.15"
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@types/express": "^4.17.13",
"@types/jest": "29.5.0",
"@types/multer": "^1.4.7",
"@types/node": "18.15.11",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"del": "^7.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"esno": "^0.16.3",
"jest": "29.5.0",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "29.0.5",
"ts-loader": "^9.2.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "4.2.0",
"typescript": "^4.7.4"
},
Relevant Database Driver(s)
- mysql
micalevisk commented
Please report this to Typeorm repository. This has nothing to do with Nest