Graphql-code-generator: Cannot execute command graphql-codegen init

Created on 5 May 2019  路  5Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug
Cannot run graphql-codegen init due to an error on Windows 10.

To Reproduce
Steps to reproduce the behavior:

  • open a PowerShell prompt
  • install with yarn global add @graphql-codegen/cli
  • run graphql-codegen init

Expected behavior
The command to execute correctly ...

Environment:

  • OS: Windows 10
  • @graphql-codegen/...: graphql-codegen/cli
  • NodeJS: v10.9.0

Additional context
Error with powershell:

At C:\Users\adrie\AppData\Local\Yarn\bin\graphql-codegen.ps1:5 char:13
+     *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
+             ~
Unexpected token ')' in expression or statement.
At C:\Users\adrie\AppData\Local\Yarn\bin\graphql-codegen.ps1:8 char:3
+ if [ -x "$basedir/pwsh" ]; then
+   ~
Missing '(' after 'if' in if statement.
At C:\Users\adrie\AppData\Local\Yarn\bin\graphql-codegen.ps1:8 char:5
+ if [ -x "$basedir/pwsh" ]; then
+     ~
Missing type name after '['.
At C:\Users\adrie\AppData\Local\Yarn\bin\graphql-codegen.ps1:9 char:20
+ ... edir/pwsh"  "$basedir/../Data/global/node_modules/.bin/graphql-codege ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '"$basedir/../Data/global/node_modules/.bin/graphql-codegen.ps1"' in expression or statement.
At C:\Users\adrie\AppData\Local\Yarn\bin\graphql-codegen.ps1:9 char:84
+ ...  "$basedir/../Data/global/node_modules/.bin/graphql-codegen.ps1" "$@"
+                                                                      ~~~~
Unexpected token '"$@"' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

Error with powershell core 6:

At C:\Users\adrie\AppData\Local\Yarn\bin\graphql-codegen.ps1:4 char:6
+ case `uname` in
+      ~~
The Unicode escape sequence is not valid. A valid sequence is `u{ followed by one to six hex digits and a closing '}'.
At C:\Users\adrie\AppData\Local\Yarn\bin\graphql-codegen.ps1:5 char:13
+     *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
+             ~
Unexpected token ')' in expression or statement.
At C:\Users\adrie\AppData\Local\Yarn\bin\graphql-codegen.ps1:8 char:3
+ if [ -x "$basedir/pwsh" ]; then
+   ~
Missing '(' after 'if' in if statement.
At C:\Users\adrie\AppData\Local\Yarn\bin\graphql-codegen.ps1:8 char:5
+ if [ -x "$basedir/pwsh" ]; then
+     ~
Missing type name after '['.
At C:\Users\adrie\AppData\Local\Yarn\bin\graphql-codegen.ps1:9 char:20
+ ... edir/pwsh"  "$basedir/../Data/global/node_modules/.bin/graphql-codege ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '"$basedir/../Data/global/node_modules/.bin/graphql-codegen.ps1"' in expression or statement.
At C:\Users\adrie\AppData\Local\Yarn\bin\graphql-codegen.ps1:9 char:84
+ ...  "$basedir/../Data/global/node_modules/.bin/graphql-codegen.ps1" "$@"
+                                                                      ~~~~
Unexpected token '"$@"' in expression or statement.
+ CategoryInfo          : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : InvalidUnicodeEscapeSequence

bug core

All 5 comments

I found a "workaround". By using graphql-codegen.cmd init it works (using the cmd script instead of the ps1 script).

@pellea the .ps script is created by Yarn, so I'm not sure it's related to the codegen (maybe we missed something?).
Anyway, I don't have Windows environment, so it might be difficult for me for to fix that soon :(

@pellea It seems like there are some issue with Yarn and PowerShell.
Can you please try to take a look at this issue?
https://github.com/yarnpkg/yarn/issues/6902

I think they already solved it in the latest version.

The graphql-codegen init command is working with Yarn 1.15.2. Thx for pointing out the other issue.

I'd recommend using WSL to avoid issues like this.

Was this page helpful?
0 / 5 - 0 ratings