Expo Web 无法编译“可选链接”

suj*_*lin 10 javascript optional-chaining react-native-web expo react-native-ui-kitten

看起来 Expo Webpack 没有optional chaining

当我尝试将UI Kitten安装到 Expo Web 应用程序时,我发现了这一点。

这是我将 UI Kitten 添加到新创建的 Expo 应用程序后的编译错误

node_modules/@ui-kitten/components/ui/input/input.component.js 104:38
Module parse failed: Unexpected token (104:38)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|         this.webEventResponder = devsupport_1.WebEventResponder.create(this);
|         this.focus = () => {
>             this.textInputRef.current?.focus();
|         };
|         this.blur = () => {
Run Code Online (Sandbox Code Playgroud)

Deps 版本(我在这里写的那一刻的最新版本。)

  • expo@37.0.6
  • @ui-kitten/components@5.0.0-alpha.1

有什么技巧可以解决这个问题?

con*_*exo 5

Webpack 使用 Acorn 解析器,并且Acorn 目前不支持可选链接

有一个待处理的拉取请求,您可以订阅该请求以获得有关进度的通知

因此,您的解决方法选项是:

  • 不使用 webpack
  • 不要使用可选链
  • 将 Babel 集成到您的堆栈中,并确保使用此Babel 插件首先通过 Babel 传递所有 *.js 文件
  • 等待上述 PR 合并并发布包含此 PR 的下一个版本
  • fork Acorn,自己合并 PR,然后 fork webpack 并让它使用你的 fork Acorn

  • 我的最终目标是将“UI Kitten”安装到 Expo Web 应用程序。有没有办法解决这个问题?也许添加任何其他第 3 方 webpack 加载器到配置中?Expo 通常使用 Babel,但仅用于移动构建。对于 Web 构建,它使用“Webpack”。无法避免在 Expo 中构建 Webpack。 (4认同)