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: Cannot read property 'replace' of undefined" on running the cli query command with several SQL statements #6612

Closed
nosteiner opened this issue Aug 24, 2020 · 7 comments · Fixed by #6910

Comments

@nosteiner
Copy link
Contributor

Issue type:

[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:

On running the cli query command with several SQL statements all wrapped with double quotes I receive the following error from the cli-highlight:

> ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli --config ormconfig-migrations.ts "query" "SELECT * FROM folder;
SELECT * FROM sub_folder;"

Running query: SELECT * FROM folder;
SELECT * FROM sub_folder;
Query has been executed. Result: 
Error during query execution:
TypeError: Cannot read property 'replace' of undefined
    at escape (/usr/src/app/node_modules/highlight.js/lib/highlight.js:71:18)
    at Object.highlight (/usr/src/app/node_modules/highlight.js/lib/highlight.js:799:18)
    at Object.highlight (/usr/src/app/node_modules/cli-highlight/src/index.ts:97:21)
    at Function.PlatformTools.highlightJson (/usr/src/app/src/platform/PlatformTools.ts:221:16)
    at Object.<anonymous> (/usr/src/app/src/commands/QueryCommand.ts:55:39)
    at step (/usr/src/app/node_modules/typeorm/node_modules/tslib/tslib.js:141:27)
    at Object.next (/usr/src/app/node_modules/typeorm/node_modules/tslib/tslib.js:122:57)
    at fulfilled (/usr/src/app/node_modules/typeorm/node_modules/tslib/tslib.js:112:62)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sindy@1.0.0 typeorm: `ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli --config ormconfig-migrations.ts "query" "SELECT * FROM folder;
npm ERR! SELECT * FROM sub_folder;"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the sindy@1.0.0 typeorm script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-08-24T13_13_49_857Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sindy@1.0.0 rls:on: `bash src/policies/enable-rls.sh`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the sindy@1.0.0 rls:on script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-08-24T13_13_49_873Z-debug.log

@IAL32
Copy link

IAL32 commented Nov 14, 2020

Unfortunately, I still have the same error:
TypeORM version: 0.2.29

image

Please ignore the first line, where I generate the ormconfig based on my current .env

The error comes up for every query, not just SELECT

@xiniria
Copy link
Contributor

xiniria commented Dec 1, 2020

I also have this problem, is it possible to re-open the issue?

➜ npm run typeorm query "\"DROP DATABASE IF EXISTS 'air_monitoring';\""

> air-monitoring-backend@0.0.1 typeorm /Users/raphael/Documents/Code/projet-3a/air-monitoring-backend
> node --require ts-node/register ./node_modules/typeorm/cli.js "query" "DROP DATABASE IF EXISTS 'air_monitoring';"

Error during query execution:
TypeError: Cannot read property 'replace' of undefined
    at escapeHTML (/Users/raphael/Documents/Code/projet-3a/air-monitoring-backend/node_modules/highlight.js/lib/core.js:53:6)
    at _highlight (/Users/raphael/Documents/Code/projet-3a/air-monitoring-backend/node_modules/highlight.js/lib/core.js:1878:18)
    at Object.highlight (/Users/raphael/Documents/Code/projet-3a/air-monitoring-backend/node_modules/highlight.js/lib/core.js:1465:7)
    at Object.highlight (/Users/raphael/Documents/Code/projet-3a/air-monitoring-backend/node_modules/cli-highlight/src/index.ts:97:21)
    at Function.PlatformTools.highlightSql (/Users/raphael/Documents/Code/projet-3a/air-monitoring-backend/src/platform/PlatformTools.ts:213:16)
    at Object.<anonymous> (/Users/raphael/Documents/Code/projet-3a/air-monitoring-backend/src/commands/QueryCommand.ts:56:72)
    at step (/Users/raphael/Documents/Code/projet-3a/air-monitoring-backend/node_modules/typeorm/node_modules/tslib/tslib.js:141:27)
    at Object.next (/Users/raphael/Documents/Code/projet-3a/air-monitoring-backend/node_modules/typeorm/node_modules/tslib/tslib.js:122:57)
    at fulfilled (/Users/raphael/Documents/Code/projet-3a/air-monitoring-backend/node_modules/typeorm/node_modules/tslib/tslib.js:112:62)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

@nbaillie
Copy link

nbaillie commented Dec 2, 2020

Also having this issue, are there any workarounds?

@enilsonandrade
Copy link

My workaround is to pin to version "typeorm": "0.2.25". It'd be nice to get this fixed in the later versions

@prokopsimek
Copy link

Same issue here

zaro pushed a commit to zaro/typeorm that referenced this issue Jan 12, 2021
@initplatform
Copy link

Reverting back to 0.2.28 worked for me

@kongnakornna
Copy link

kongnakornna commented Jul 5, 2022

i Same issue here

import { EntityRepository, Repository ,EntityManager} from "typeorm";
import { SdUsers } from "../entities/SdUsers.entity";
import { SdUsersPdpaAllow } from "../entities/SdUsersPdpaAllow.entity";
import { SdUserRoles } from "../entities/SdUserRoles.entity";
@entityrepository(SdUsers)
export class SdUsersRepository extends Repository{
async getWhereRs(filter: any) {


run code is issue here

{"statusCode":500},"err":{"type":"TypeError","message":"Cannot read property 'replace' of undefined","stack":"TypeError: Cannot read property 'replace' of undefined\n at D:\UwAmp\www\aDEV\fastify_api\src\modules\user\controllers\usercontroller.ts:57:30\n at step (D:\UwAmp\www\aDEV\fastify_api\src\modules\user\controllers\usercontroller.ts:33:23)\n at Object.next (D:\UwAmp\www\aDEV\fastify_api\src\modules\user\controllers\usercontroller.ts:14:53)\n at D:\UwAmp\www\aDEV\fastify_api\src\modules\user\controllers\usercontroller.ts:8:71\n at new Promise ()\n at __awaiter (D:\UwAmp\www\aDEV\fastify_api\src\modules\user\controllers\usercontroller.ts:4:12)\n at Object.
(D:\UwAmp\www\aDEV\fastify_api\src\modules\user\controllers\usercontroller.ts:45:69)\n at preHandlerCallback (D:\UwAmp\www\aDEV\fastify_api\node_modules\fastify\lib\handleRequest.js:126:28)\n at preValidationCallback (D:\UwAmp\www\aDEV\fastify_api\node_modules\fastify\lib\handleRequest.js:109:5)\n at handler (D:\UwAmp\www\aDEV\fastify_api\node_modules\fastify\lib\handleRequest.js:72:7)"},"msg":"Cannot read property 'replace' of undefined"}
{"level":30,"time":1657020822176,"pid":25656,"hostname":"kongnakorn01","reqId":"req-1","res":{"statusCode":500},"responseTime":18.17069999873638,"msg":"request completed"}

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.

9 participants