Skip to content
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

[0.2.27] Regression: CLI migration:create fails with "TypeError: Cannot read property 'startsWith' of undefined" #6831

Closed
constb opened this issue Oct 2, 2020 · 2 comments · Fixed by #6836

Comments

@constb
Copy link
Contributor

constb commented Oct 2, 2020

Issue type:

[*] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[*] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[*] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

Run (with TYPEORM_MIGRATIONS_DIR=src/migrations in .env):
node --require ts-node/register ./node_modules/typeorm/cli.js -- migration:create -n SomeName
Or even:
TYPEORM_MIGRATIONS_DIR=src/migrations node --require ts-node/register ./node_modules/typeorm/cli.js -- migration:create -n SomeName

Neither works. Only if I specify -d migration dir argument explicitly, it would create that migration.

Complete error output follows:

$ npm run typeorm -- migration:create -n SomeName

> xxx@0.0.1 typeorm /…/xxx
> node --require ts-node/register ./node_modules/typeorm/cli.js "migration:create" "-n" "SomeName"

Error during migration creation:
TypeError: Cannot read property 'startsWith' of undefined
    at Object.<anonymous> (/.../node_modules/.pnpm/typeorm@0.2.27/src/commands/MigrationCreateCommand.ts:62:37)
    at step (/.../node_modules/.pnpm/tslib@1.13.0/node_modules/tslib/tslib.js:141:27)
    at Object.throw (/.../node_modules/.pnpm/tslib@1.13.0/node_modules/tslib/tslib.js:122:57)
    at rejected (/.../node_modules/.pnpm/tslib@1.13.0/node_modules/tslib/tslib.js:113:69)
 ERROR  Command failed with exit code 1.
@imnotjames
Copy link
Contributor

imnotjames commented Oct 2, 2020

Issue is that while we're saying the variable directory is a string.. it's not. It's possibly undefined - and via some edge cases it may remain undefined.

However, that edge case is that it can't find the configuration.

Three things would be helpful here

  • Fix the edge case in all the create commands to prevent this undefined value from getting through
  • Update the typing to better reflect the value of the variable.
  • Add debug logging whenever we load a configuration file in commands because this is a common theme that the connection options don't get read as expected.

@imnotjames
Copy link
Contributor

Ah, there's no verbosity or debug logger for these. That's a bummer.

imnotjames added a commit to imnotjames/typeorm that referenced this issue Oct 2, 2020
in some cases - where the connection options couldn't be read -
we would end up with the migration:create and similar commands
failing with a TypeError

this refactors the create commands a bit to defend against
an undefined directory, preventing the TypeError

fixes typeorm#6831
imnotjames added a commit to imnotjames/typeorm that referenced this issue Oct 2, 2020
in some cases - where the connection options couldn't be read -
we would end up with the migration:create and similar commands
failing with a TypeError

this refactors the create commands a bit to defend against
an undefined directory, preventing the TypeError

fixes typeorm#6831
pleerock pushed a commit that referenced this issue Oct 6, 2020
in some cases - where the connection options couldn't be read -
we would end up with the migration:create and similar commands
failing with a TypeError

this refactors the create commands a bit to defend against
an undefined directory, preventing the TypeError

fixes #6831
zaro pushed a commit to zaro/typeorm that referenced this issue Jan 12, 2021
in some cases - where the connection options couldn't be read -
we would end up with the migration:create and similar commands
failing with a TypeError

this refactors the create commands a bit to defend against
an undefined directory, preventing the TypeError

fixes typeorm#6831
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants