[GH-ISSUE #22] Error with JSON Parsing and Undefined Property Access When Unminifying JavaScript with Humanify #20

Closed
opened 2026-03-03 13:52:15 +03:00 by kerem · 5 comments
Owner

Originally created by @abdurrahim11 on GitHub (Jul 30, 2024).
Original GitHub issue: https://github.com/jehna/humanify/issues/22

I am facing problem while running one of my big script first everything is fine then after some time it gives below error

my minify js link: https://drive.google.com/file/d/1QHHRw_YKbYwgf7rbT8R8qP6Uh5BxNZ4l/view?usp=sharing

echo "OPENAI_TOKEN=sk-proj-MsUzhNo4jhbzk9zziiKET.............." > .env && npm start -- -o admin.js admin.min.js
export OPENAI_TOKEN="sk-proj-MsUzhNo4jhbzk9zziiKET.............." && npm start -- -o admin.js admin.min.js
OPENAI_TOKEN=sk-proj-MsUzhNo4jhbzk9zziiKET.............. npm start -- -o admin.js admin.min.js
npm start -- --key="sk-proj-MsUzhNo4jhbzk9zziiKET.............." -o admin.js admin.min.js
undefined:351
...
^

SyntaxError: Unexpected token '.', ..."E" },
...
]
}" is not valid JSON
at JSON.parse ()
at codeToVariableRenames (/home/abdurrahimcoder/humanify-main/src/openai/openai.ts:76:59)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at (/home/abdurrahimcoder/humanify-main/src/openai/openai.ts:21:23)
at async Promise.all (index 1)
at mapPromisesParallel (/home/abdurrahimcoder/humanify-main/src/openai/run-promises-in-parallel.ts:17:5)
at client.createChatCompletion.model (/home/abdurrahimcoder/humanify-main/src/openai/openai.ts:20:5)
at (/home/abdurrahimcoder/humanify-main/src/index.ts:68:25)

Node.js v20.15.1

/home/abdurrahimcoder/humanify-main/src/openai/rename-variables-and-functions.ts:17
const rename = toRename.find((r) => r.name === path.node.name);
^

TypeError: unknown file: Cannot read properties of undefined (reading 'name')
at (/home/abdurrahimcoder/humanify-main/src/openai/rename-variables-and-functions.ts:17:49)
at Array.find ()
at PluginPass.Identifier (/home/abdurrahimcoder/humanify-main/src/openai/rename-variables-and-functions.ts:17:35)
at newFn (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/visitors.ts:292:14)
at _call (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:35:20)
at call (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:20:17)
at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:94:31)
at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16)
at visitMultiple (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:98:17)
at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:174:19)
at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17)
at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:101:33)
at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16)
at visitSingle (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:108:19)
at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:176:19)
at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17)
at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:101:33)
at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16)
at visitSingle (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:108:19)
at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:176:19)
at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17)
at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:101:33)
at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16)
at visitSingle (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:108:19)
at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:176:19)
at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17)
at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:101:33)
at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16)
at visitMultiple (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:98:17)
at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:174:19)
at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17)
at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:101:33)
at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16)
at visitSingle (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:108:19)
at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:176:19)
at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17)
at traverse (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/index.ts:82:15)
at transformFile (/home/abdurrahimcoder/humanify-main/node_modules/@babel/core/src/transformation/index.ts:120:13)
at transformFile.next ()
at run (/home/abdurrahimcoder/humanify-main/node_modules/@babel/core/src/transformation/index.ts:47:12)
at run.next ()
at transform (/home/abdurrahimcoder/humanify-main/node_modules/@babel/core/src/transform.ts:29:20)
at transform.next ()
at step (/home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:261:32)
at /home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:273:13
at async.call.result.err.err (/home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:223:11)
at /home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:50:45
at step (/home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:287:14)
at /home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:273:13
at async.call.result.err.err (/home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:223:11) {
code: 'BABEL_TRANSFORM_ERROR'
}

Originally created by @abdurrahim11 on GitHub (Jul 30, 2024). Original GitHub issue: https://github.com/jehna/humanify/issues/22 I am facing problem while running one of my big script first everything is fine then after some time it gives below error my minify js link: https://drive.google.com/file/d/1QHHRw_YKbYwgf7rbT8R8qP6Uh5BxNZ4l/view?usp=sharing echo "OPENAI_TOKEN=sk-proj-MsUzhNo4jhbzk9zziiKET.............." > .env && npm start -- -o admin.js admin.min.js export OPENAI_TOKEN="sk-proj-MsUzhNo4jhbzk9zziiKET.............." && npm start -- -o admin.js admin.min.js OPENAI_TOKEN=sk-proj-MsUzhNo4jhbzk9zziiKET.............. npm start -- -o admin.js admin.min.js npm start -- --key="sk-proj-MsUzhNo4jhbzk9zziiKET.............." -o admin.js admin.min.js undefined:351 ... ^ SyntaxError: Unexpected token '.', ..."E" }, ... ] }" is not valid JSON at JSON.parse (<anonymous>) at codeToVariableRenames (/home/abdurrahimcoder/humanify-main/src/openai/openai.ts:76:59) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at <anonymous> (/home/abdurrahimcoder/humanify-main/src/openai/openai.ts:21:23) at async Promise.all (index 1) at mapPromisesParallel (/home/abdurrahimcoder/humanify-main/src/openai/run-promises-in-parallel.ts:17:5) at client.createChatCompletion.model (/home/abdurrahimcoder/humanify-main/src/openai/openai.ts:20:5) at <anonymous> (/home/abdurrahimcoder/humanify-main/src/index.ts:68:25) Node.js v20.15.1 /home/abdurrahimcoder/humanify-main/src/openai/rename-variables-and-functions.ts:17 const rename = toRename.find((r) => r.name === path.node.name); ^ TypeError: unknown file: Cannot read properties of undefined (reading 'name') at <anonymous> (/home/abdurrahimcoder/humanify-main/src/openai/rename-variables-and-functions.ts:17:49) at Array.find (<anonymous>) at PluginPass.Identifier (/home/abdurrahimcoder/humanify-main/src/openai/rename-variables-and-functions.ts:17:35) at newFn (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/visitors.ts:292:14) at _call (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:35:20) at call (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:20:17) at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:94:31) at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16) at visitMultiple (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:98:17) at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:174:19) at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17) at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:101:33) at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16) at visitSingle (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:108:19) at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:176:19) at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17) at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:101:33) at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16) at visitSingle (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:108:19) at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:176:19) at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17) at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:101:33) at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16) at visitSingle (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:108:19) at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:176:19) at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17) at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:101:33) at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16) at visitMultiple (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:98:17) at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:174:19) at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17) at NodePath.visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/path/context.ts:101:33) at visitQueue (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:144:16) at visitSingle (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:108:19) at visit (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/context.ts:176:19) at traverseNode (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/traverse-node.ts:40:17) at traverse (/home/abdurrahimcoder/humanify-main/node_modules/@babel/traverse/src/index.ts:82:15) at transformFile (/home/abdurrahimcoder/humanify-main/node_modules/@babel/core/src/transformation/index.ts:120:13) at transformFile.next (<anonymous>) at run (/home/abdurrahimcoder/humanify-main/node_modules/@babel/core/src/transformation/index.ts:47:12) at run.next (<anonymous>) at transform (/home/abdurrahimcoder/humanify-main/node_modules/@babel/core/src/transform.ts:29:20) at transform.next (<anonymous>) at step (/home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:261:32) at /home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:273:13 at async.call.result.err.err (/home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:223:11) at /home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:50:45 at step (/home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:287:14) at /home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:273:13 at async.call.result.err.err (/home/abdurrahimcoder/humanify-main/node_modules/gensync/index.js:223:11) { code: 'BABEL_TRANSFORM_ERROR' }
kerem closed this issue 2026-03-03 13:52:16 +03:00
Author
Owner

@jehna commented on GitHub (Jul 30, 2024):

SyntaxError: Unexpected token '.', ..."E" },

This is very probably the same issue as https://github.com/jehna/humanify/issues/12

<!-- gh-comment-id:2259102840 --> @jehna commented on GitHub (Jul 30, 2024): > SyntaxError: Unexpected token '.', ..."E" }, This is very probably the same issue as https://github.com/jehna/humanify/issues/12
Author
Owner
<!-- gh-comment-id:2261898867 --> @0xdevalias commented on GitHub (Aug 1, 2024): Potentially related: - https://github.com/jehna/humanify/issues/12 - https://github.com/jehna/humanify/issues/17 - https://github.com/jehna/humanify/issues/18
Author
Owner

@jehna commented on GitHub (Aug 11, 2024):

This should now be fixed in v2 since there's the long awaited JSON mode with the new structured outputs. Please take a look and repoen if anything comes up

<!-- gh-comment-id:2282876269 --> @jehna commented on GitHub (Aug 11, 2024): This should now be fixed in v2 since there's the long awaited JSON mode with the new [structured outputs](https://openai.com/index/introducing-structured-outputs-in-the-api/). Please take a look and repoen if anything comes up
Author
Owner

@tkreuder commented on GitHub (Sep 16, 2024):

@jehna Thanks a lot for providing that tool!!

I using humanify 2.1.2 but still face the issue.

code: 'BABEL_PARSE_ERROR',
reasonCode: 'UnexpectedToken',
loc: Position { line: 17261, column: 14, index: 542664 },
pos: 542664,
syntaxPlugin: undefined

<!-- gh-comment-id:2353751546 --> @tkreuder commented on GitHub (Sep 16, 2024): @jehna Thanks a lot for providing that tool!! I using humanify 2.1.2 but still face the issue. code: 'BABEL_PARSE_ERROR', reasonCode: 'UnexpectedToken', loc: Position { line: 17261, column: 14, index: 542664 }, pos: 542664, syntaxPlugin: undefined
Author
Owner

@0xdevalias commented on GitHub (Sep 17, 2024):

code: 'BABEL_PARSE_ERROR',
reasonCode: 'UnexpectedToken',

@tkreuder I'm not 100%, but I believe this may be a separate issue to the above. It sounds like the error is happening during the babel parsing of the code, not the JSON parsing. To debug it further, I suspect the code you're trying to to unminify will be needed (or at the very least, tracking down what part of the code is being referenced there as being unexpected. Given it's happening in the babel area of things, there's also a chance that this may be a bug/unsupported edge case in webcrack (which this tool uses for unminification)

<!-- gh-comment-id:2354337566 --> @0xdevalias commented on GitHub (Sep 17, 2024): > code: 'BABEL_PARSE_ERROR', > reasonCode: 'UnexpectedToken', @tkreuder I'm not 100%, but I believe this may be a separate issue to the above. It sounds like the error is happening during the babel parsing of the code, not the JSON parsing. To debug it further, I suspect the code you're trying to to unminify will be needed (or at the very least, tracking down what part of the code is being referenced there as being unexpected. Given it's happening in the babel area of things, there's also a chance that this may be a bug/unsupported edge case in webcrack (which this tool uses for unminification)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/humanify#20
No description provided.