question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[CLI] SyntaxError: JSON5: invalid character with verbatim command copied from squoosh.app

See original GitHub issue

Describe the bug Copying resize commands from squoosh.app and trying to use them results in SyntaxError and aborted processing.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://squoosh.app/editor
  2. Enable resize
  3. Copy command
  4. Open a terminal
  5. Paste the command and append an image file name in that directory
  6. Press Enter

Expected behavior File is squooshed with those settings Actual:

(node:28880) UnhandledPromiseRejectionWarning: SyntaxError: JSON5: invalid character 'l' at 1:45
    at syntaxError (C:\Users\herbst\AppData\Roaming\npm\node_modules\@squoosh\cli\node_modules\json5\lib\parse.js:1083:17)
    at invalidChar (C:\Users\herbst\AppData\Roaming\npm\node_modules\@squoosh\cli\node_modules\json5\lib\parse.js:1028:12)
    at Object.value (C:\Users\herbst\AppData\Roaming\npm\node_modules\@squoosh\cli\node_modules\json5\lib\parse.js:287:15)
    at lex (C:\Users\herbst\AppData\Roaming\npm\node_modules\@squoosh\cli\node_modules\json5\lib\parse.js:78:42)
    at Object.parse (C:\Users\herbst\AppData\Roaming\npm\node_modules\@squoosh\cli\node_modules\json5\lib\parse.js:25:17)
    at Command.processFiles (file:///C:/Users/herbst/AppData/Roaming/npm/node_modules/@squoosh/cli/src/index.js:137:49)
(node:28880) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:28880) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that

Example command that fails (copied from squoosh.app + " file.jpg"):

npx @squoosh/cli --resize '{"enabled":true,"width":1024,"height":1024,"method":"lanczos3","fitMethod":"stretch","premultiply":true,"linearRGB":true}' --mozjpeg '{"quality":75,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75} file.jpg

Version:

  • OS w/ version: [e.g. iOS 12]
  • Browser w/ version [e.g. Chrome 70]
  • Node version: [e.g. 10.11.0]
  • npm version: [e.g. 6.4.1]

Is your issue related to the quality of image compression? Please attach original and output images (you can drag & drop to attach).

  • Original image
  • Output image from Squoosh

Additional context, screenshots, screencasts Add any other context about the problem here.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
surmacommented, Nov 16, 2021

Seems like there is ' missing. I’ll take a look.

- npx @squoosh/cli --resize '{"enabled":true,"width":1024,"height":1024,"method":"lanczos3","fitMethod":"stretch","premultiply":true,"linearRGB":true}' --mozjpeg '{"quality":75,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75} file.jpg
+ npx @squoosh/cli --resize '{"enabled":true,"width":1024,"height":1024,"method":"lanczos3","fitMethod":"stretch","premultiply":true,"linearRGB":true}' --mozjpeg '{"quality":75,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75}' file.jpg
0reactions
DukeBJcommented, Sep 16, 2022

on Windows delete keys “method”:“lanczos3”,“fitMethod”:“stretch” at JSON

UPD: OS: windows 10 SMD: powershell 7.2.1 NODE: 14.19.3

If you have keys with string parameters, like "method":"lanczos3" or "fitMethod":"stretch". You need to escape quotes from the key value, like "method":\"lanczos3\" or "fitMethod":\"stretch\". It’s work!

UPD2:

It’s work only on squoosh-cli (squoosh install global). Method npx @squoosh/cli dosen’t work.

Example:

squoosh-cli -s '@2560px' -d '.\done\' --resize '{"enabled":true,"width":2560,"height":1440,"premultiply":true,"linearRGB":true,"method":\"lanczos3\", "fitMethod":\"contain\"}' --mozjpeg '{"quality":60,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75}' file-name.png

IMPORTANT:

fitMethod: contain doesn’t work on Windows in cli mode.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error while parsing config - JSON5: invalid end of input at 1:1 ...
I have tried using the node_modules/.bin/babel before.js -o after.js command to convert from es6 to compatible js.
Read more >
[CLI] SyntaxError: JSON5: invalid character with verbatim command ...
Go to https://squoosh.app/editor; Enable resize; Copy command; Open a terminal; Paste the command and append an image file name in that directory; Press...
Read more >
I'm getting this error and can't seem to google my way ... - Reddit
Please run next command `yarn upgrade` SyntaxError: JSON5: invalid end of input at 1:1 at syntaxError (/mnt/d/Coding/projects/nextjs-blog/ ...
Read more >
squoosh - bytemeta
[Web] Dragging a new image into squoosh.app resets resize settings ... [CLI] SyntaxError: JSON5: invalid character with verbatim command copied from ...
Read more >
Promise { <rejected> { SyntaxError: JSON5: invalid character ...
Unhandled Rejection at: Promise { { SyntaxError: JSON5: invalid character ... The missing documentation tool for your Angular, Nest & Stencil application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found