【问题标题】:React-Native/Expo/Cygwin “Unexpected Token” ProblemReact-Native/Expo/Cygwin “意外令牌”问题
【发布时间】:2019-02-19 07:04:23
【问题描述】:

安装 react-devtools 后,我无法再运行 expo-cli。 在我这样做之前,一切都很好。我现在收到以下错误。 我的 Powershell 权限也更改为“受限”。我已将注册表恢复到前一天,并已卸载/重新安装 node 和 yarn 以解决此问题。

错误列出了我的计算机上没有安装的 Cygwin(未显示在注册表搜索中),但是,搜索我的计算机,我看到 Cygwin 是随 Git 一起安装的:

C:\Program Files\Git\usr\share\cygwin
C:\Program Files\Git\usr\bin\cygwin-console-helper.exe
C:\Program Files\Android\Android Studio\bin\lldb\lib\distutils\cygwinccompiler.py
C:\Program Files\Git\usr\lib\perlS\core_per|\File\Spec\cygwin.pm
C:\Program Files\Git\usr\share\cygwin\cygwin.ldif
C:\Program Files\Git\usr\share\tern1info\63\cygwin
C:\Program Files\Git\usr\lib\terminf0\63\cygwin

任何帮助将不胜感激。
视窗 10
npm:6.6.0
节点:v10.15.0
纱线:v1.13.0

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

@supermerio

C:\Users\name\AppData\Local\Yarn\bin\expo.ps1

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/pwsh" ]; then
  "$basedir/pwsh"  "$basedir/../Data/global/node_modules/.bin/expo.ps1" "$@"
  ret=$?
else 
  pwsh  "$basedir/../Data/global/node_modules/.bin/expo.ps1" "$@"
  ret=$?
fi
exit $ret

此外,我可以通过将 expo 安装到我的 repo 中并从那里调用它来使其正常工作。 我注意到本地脚本与全局安装中的脚本有所不同。本地脚本调用“node”,而全局脚本(上图)调用“pwsh”。

\LactFacts\lactfact_190118\node_modules.bin\expo:

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/../expo-cli/bin/expo.js" "$@"
  ret=$?
else 
  node  "$basedir/../expo-cli/bin/expo.js" "$@"
  ret=$?
fi
exit $ret

【问题讨论】:

    标签: powershell react-native cygwin expo


    【解决方案1】:

    这是一个已知的 Yarn 1.13.0 问题:https://github.com/yarnpkg/yarn/issues/6902#issuecomment-453534280

    【讨论】:

      【解决方案2】:

      看起来“C:\Users\name\AppData\Local\Yarn\bin\expo.ps1”中的任何内容都有一个格式错误的 if 语句。

      您能否查看该文件以确认?如果可能,请在此处发布。

      【讨论】:

      • 无法格式化 cmets,所以我在上面的 OP 中发布。谢谢。
      • expo.ps1 中的代码不是 powershell,尽管它似乎试图被解释为这样。
      猜你喜欢
      • 2020-09-12
      • 1970-01-01
      • 2016-07-16
      • 2016-11-04
      • 1970-01-01
      • 2013-02-11
      • 2018-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多