-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Issue Description
Generating js migration files via CLI with --outputJs produces an unused import from typeorm.
I'm running the command: npm run typeorm -- migration:generate src/migrations/migration --dataSource src/datasource.ts --pretty --outputJs
Which produces a file src/migrations/12345-migration.js file as expected, and works with the migration:run command locally. However, the file contains unused require referring to the MigrationInterface and QueryRunner on the first line:
const { MigrationInterface, QueryRunner } = require("typeorm");
module.exports = class migration12345 {
name = 'migration12345';
...etcThis causes 2 problems for me, although I'm sure there are other manifestations of this problem too.
- It fails eslint
no-unused-varsrule - I am running these migrations in an AWS lambda function.
Typeormis bundled with the migration lambda function code using esbuild. The migrations cannot be bundled unfortunately due to esbuild not being to resolve the imports from the migrations directory glob at build time. Therefore, the lambda fails when running migrations because the imported migration file does not have access totypeormdependency (its bundled with the migration code).
"errorMessage": "Cannot find module 'typeorm'\nRequire stack:\n- /var/task/src/migrations/12345-migration.js\n- /var/task/src/handlers/migrate/index.js\n- /var/runtime/index.mjs",
There are 2 workarounds to this for me:
- Exclude typeorm dependency from the bundle (not keen on doing this)
- Manually remove the
requirestatement
Obviously number 2 is preferred for now, but it would be great if the line wasn't generated at all!
Expected Behavior
The line const { MigrationInterface, QueryRunner } = require("typeorm"); should be omitted from generated js migration files.
Are you willing to resolve this issue by submitting a Pull Request?
- ✖️ Yes, I have the time, and I know how to start.
- ✅ Yes, I have the time, but I don't know how to start. I would need guidance.
- ✖️ No, I don’t have the time, but I can support (using donations) development.
- ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.