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

TypeError: str.replace is not a function #4798

Closed
joalorro opened this issue Sep 23, 2019 · 2 comments
Closed

TypeError: str.replace is not a function #4798

joalorro opened this issue Sep 23, 2019 · 2 comments

Comments

@joalorro
Copy link

joalorro commented Sep 23, 2019

Issue type:

[ ] question
[x ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

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

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:
https://github.com/joalorro/typeorm-cli-bug

I'm currently attempting to have a Node file programmatically generate migrations via the TypeORM CLI, but I get the error "TypeError: str.replace is not a function". When running the same command via NPM, the migration is successfully created.

I console.log'd the variable "args" within MigrationGenerateCommand.js on line 92 (below "case 8:") and found that it looks like:

{
  _: [ 'migration:generate', 'initial' ], // extra element
  config: 'ormconfig.json',
  f: 'ormconfig.json',
  n: true, // bolean
  name: true, //boolean
  c: 'default',
  connection: 'default',
  '$0': 'node_modules/typeorm/cli.js'
 }

when it should look like:

{
  _: [ 'migration:generate' ],
  config: 'ormconfig.json',
  f: 'ormconfig.json',
  n: 'initial', //string
  name: 'initial', //string
  c: 'default',
  connection: 'default',
  '$0': 'node_modules/typeorm/cli.js'
 }

The latter object is produced when running the package.json scripts, and String.replace is attempting to run on args.name, which is now a boolean.

Node command: node migration.js initial
NPM command: npm run typeorm:migrate initial

// package.json
{
  ...,
  scripts: {
  ...,
    "typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config ormconfig.json",
    "typeorm:migrate": "npm run typeorm migration:generate -- -n",
  }
}
@ali-master
Copy link

Any solution?

@pppdns
Copy link

pppdns commented Apr 2, 2020

#2719, #4805

akosasante pushed a commit to akosasante/typeorm that referenced this issue Sep 9, 2020
enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: typeorm#2719, typeorm#4798, typeorm#4805
akosasante pushed a commit to akosasante/typeorm that referenced this issue Sep 9, 2020
…ssing name argument

enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: typeorm#2719, typeorm#4798, typeorm#4805
pleerock pushed a commit that referenced this issue Sep 26, 2020
* fix: enforce name argument of migration generate command

enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: #2719, #4798, #4805

* fix: update error message text for generate migration command when missing name argument

enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: #2719, #4798, #4805

Co-authored-by: Akosua Asante <akosuaasante@gmail.com>
zaro pushed a commit to zaro/typeorm that referenced this issue Jan 12, 2021
… (typeorm#6690)

* fix: enforce name argument of migration generate command

enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: typeorm#2719, typeorm#4798, typeorm#4805

* fix: update error message text for generate migration command when missing name argument

enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: typeorm#2719, typeorm#4798, typeorm#4805

Co-authored-by: Akosua Asante <akosuaasante@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants