Giter Site home page Giter Site logo

Comments (14)

aristotelos avatar aristotelos commented on May 17, 2024 2

I just found out what is a solution here: enclose the value in double quotes like this:

npx angular-prerender --parameter-values '\"{\\\":name\\\":[\\\"am e l i a\\\",\\\"o l i v e r\\\"]}\"'

from angular-prerender.

chrisguttandin avatar chrisguttandin commented on May 17, 2024

Hi @aristotelos, thanks for bringing this to my attention. I can't reproduce the problem which is why I have the feeling that this could be an incompatibility between macOS and Windows.

Does it work if you use some other type of quotes?

from angular-prerender.

aristotelos avatar aristotelos commented on May 17, 2024

Well, PowerShell has single quotes as its standard escape character, so this seems the best option. I also tried with double quotes like this, but it fails:

PS C:\mydir> npx angular-prerender --parameter-values "'{`":name`":[`"amelia`",`"oliver`"]}'"
Opties:
  --version           Toon versienummer                              [booleaans]
  --help              Toon help                                      [booleaans]
  --browser-target    specify the target inside your angular.json file which is
                      used to build the single page app
                                                   [string] [standaard: "build"]
                                                            [string] [standaard:
               "C:\mydir\angular.json"]
  --parameter-values  specify the parameter values which should be replaced with
                      the parameter in the routes     [string] [standaard: "{}"]
  --server-target     specify the target inside your angular.json file which is
                      used to build the server side code
                                                  [string] [standaard: "server"]
  --verbose, -v       set this flag if you prefer more detailed log messages

Unexpected token : in JSON at position 1

Even simple JSON like this fails:

PS C:\mydir> npx angular-prerender --parameter-values '{"foo":"bar"}'
Opties:
  --version           Toon versienummer                              [booleaans]
  --help              Toon help                                      [booleaans]
  --browser-target    specify the target inside your angular.json file which is
                      used to build the single page app
                                                   [string] [standaard: "build"]
  --config            specify the path to the angular.json file
                                                            [string] [standaard:
               "C:\mydir\angular.json"]
  --parameter-values  specify the parameter values which should be replaced with
                      the parameter in the routes     [string] [standaard: "{}"]
  --server-target     specify the target inside your angular.json file which is
                      used to build the server side code
                                                  [string] [standaard: "server"]
  --verbose, -v       set this flag if you prefer more detailed log messages
                                                  [booleaans] [standaard: false]

Unexpected token f in JSON at position 1

from angular-prerender.

chrisguttandin avatar chrisguttandin commented on May 17, 2024

Thanks for checking again. I believe now that all quotes somehow get lost. I don't know why though.

If you execute JSON.parse('{:name:[amelia,oliver]}') the error is 'SyntaxError: Unexpected token : in JSON at position 1' and if you execute JSON.parse('{foo:bar}') the error is 'Unexpected token f in JSON at position 1'. That matches with the error messages that you got.

I improved the error messages in v4.3. It will not help with the problem but it will help to verify my assumption because it logs the values as part of the error that could not be parsed.

Can you please check again with the latest version? Many thanks in advance.

from angular-prerender.

chrisguttandin avatar chrisguttandin commented on May 17, 2024

Just a quick follow up. I found this documentation for the AWS CLI. It explains how to escape JSON values for PowerShell.

https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-quoting-strings.html

Does it work if you escape all quotes with a backslash and run: npx angular-prerender --parameter-values '{\":name\":[\"amelia\",\"oliver\"]}'?

from angular-prerender.

aristotelos avatar aristotelos commented on May 17, 2024

No, it doesn't work unfortunately. I'll show a couple of commands that I tried so far with their output.

PS>npx angular-prerender --parameter-values '{\":name\":[\"amelia\",\"oliver\"]}'
Please specify valid parameter values. The given value "{:name:[amelia,oliver]}" is invalid.
PS>npx angular-prerender --parameter-values '{":name":["amelia","oliver"]}'
Please specify valid parameter values. The given value "{:name:[amelia,oliver]}" is invalid.
PS>npx angular-prerender --parameter-values "{`":name`":[`"amelia`",`"oliver`"]}"
Please specify valid parameter values. The given value "{:name:[amelia,oliver]}" is invalid.
PS>npx angular-prerender --parameter-values "{':name':['amelia','oliver']}"
Please specify valid parameter values. The given value "{':name':['amelia','oliver']}" is invalid.
PS>npx angular-prerender --parameter-values "{\`"name\`":[\`"amelia\`",\`"oliver\`"]}"
Please specify valid parameter values. The given value "{name:[amelia,oliver]}" is invalid.
PS>npx angular-prerender --parameter-values '{`\"name`\":[`\"amelia`\",`\"oliver`\"]}'
Please specify valid parameter values. The given value "{`name`:[`amelia`,`oliver`]}" is invalid.
PS>npx angular-prerender --parameter-values '{\`"name\`":[\`"amelia\`",\`"oliver\`"]}'
Please specify valid parameter values. The given value "{\`name\`:[\`amelia\`,\`oliver\`]}" is invalid.

I even tried using cmd instead, but also with no success. It seems the " characters are simply removed.

CMD>npx angular-prerender --parameter-values '{\"name\":[\"amelia\",\"oliver\"]}'
Please specify valid parameter values. The given value "{name:[amelia,oliver]}" is invalid.

from angular-prerender.

chrisguttandin avatar chrisguttandin commented on May 17, 2024

It seems like a hopeless attempt but the AWS docs say the cmd prompt should be encapsulated in double quotes. Maybe that's a combination worth trying.

npx angular-prerender --parameter-values "{\":name\":[\"amelia\",\"oliver\"]}"

Does that work?

from angular-prerender.

aristotelos avatar aristotelos commented on May 17, 2024

Tried that too, doesn't work:

CMD>npx angular-prerender --parameter-values "{\"name\":[\"amelia\",\"oliver\"]}"
Please specify valid parameter values. The given value "{name:[amelia,oliver]}" is invalid.

CMD>npx angular-prerender --parameter-values '{^"name^":[^"amelia^",^"oliver^"]}'
Please specify valid parameter values. The given value "{name:[amelia,oliver]}" is invalid.

from angular-prerender.

chrisguttandin avatar chrisguttandin commented on May 17, 2024

To be honest I have no idea, what else you could try. But I was thinking about supporting files as well. Maybe that could be a solution which works for you as well. What would you think about something like this?

npx angular-prerender --parameter-values ./my-parameter-values.json

from angular-prerender.

aristotelos avatar aristotelos commented on May 17, 2024

I have found a way! Using an escaped backslash and escaped double quote actually works, in both PowerShell and cmd:

PS>npx angular-prerender --parameter-values '{\\\":name\\\":[\\\"amelia\\\",\\\"oliver\\\"]}'

It may have to do with this issue.

from angular-prerender.

aristotelos avatar aristotelos commented on May 17, 2024

The next question is: how do I escape a space inside a parameter value...

from angular-prerender.

chrisguttandin avatar chrisguttandin commented on May 17, 2024

Wow thanks for the follow up. I will update the README once we resolved this issue.

Normally I would say don't escape whitespace at all, but I guess that doesn't work for you, right?

npx angular-prerender --parameter-values '{\\\":name\\\":[\\\"a m e l i a\\\",\\\"o l i v e r\\\"]}'

from angular-prerender.

aristotelos avatar aristotelos commented on May 17, 2024

Well, that doesn't work, it ends up with:

PS>npx angular-prerender --parameter-values '{\\\":name\\\":[\\\"a m e l i a\\\",\\\"o l i v e r\\\"]}'
Please specify valid parameter values. The given value "{":name":["a" is invalid.

I again tried one, two or three or four slashes, but that doesn't work... Because it seems to be a PowerShell or general npx issue I will close it here.

from angular-prerender.

chrisguttandin avatar chrisguttandin commented on May 17, 2024

Wow, I'm glad you found a solution. I added a small paragraph to the readme to mention that escaping might be an issue.

from angular-prerender.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.