【问题标题】:Babel not converting TypeScript in ExpoBabel 没有在 Expo 中转换 TypeScript
【发布时间】:2021-01-05 07:46:19
【问题描述】:

我正在尝试将 Cloud Functions 上传到我的 Firebase 控制台。我的应用在 Expo 上运行良好,但在尝试上传时,我认为我的代码尝试编译并抛出此错误:

Error: Error occurred while parsing your function triggers.

<root_project_directory>\node_modules\react-native\Libraries\Utilities\warnOnce.js:15
const warnedKeys: { [string]: boolean } = {};
      ^^^^^^^^^^

SyntaxError: Missing initializer in const declaration
    at wrapSafe (internal/modules/cjs/loader.js:1067:16)
    at Module._compile (internal/modules/cjs/loader.js:1115:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\Users\justi\CodingProjects\ChinesePoker\node_modules\react-native\Libraries\react-native\react-native-implementation.js:14:18)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)

这似乎是 Babel 无法识别打字稿并将其转换为 javascript 的问题,但我不确定如何解决它。我尝试分别安装@babel/plugin-transform-typescript@babel/preset-typescript,但都没有成功。有谁知道如何解决这个问题?

相关文件

babel.config.js:

module.exports = function (api) {
  api.cache(true);
  return {
    presets: [
      "@babel/preset-typescript",
      "babel-preset-expo",
    ]
  };
};

package.json:

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/native": "^5.1.6",
    "@react-navigation/stack": "^5.2.13",
    "@reduxjs/toolkit": "^1.3.5",
    "expo": "~37.0.3",
    "expo-google-app-auth": "^8.1.0",
    "firebase": "7.9.0",
    "firebaseui": "^4.5.0",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-paper": "^3.8.0",
    "react-native-safe-area-context": "^0.7.3",
    "react-native-screens": "^2.7.0",
    "react-native-svg": "^12.1.0",
    "react-native-vector-icons": "^6.6.0",
    "react-native-web": "~0.11.7",
    "react-redux": "^7.2.0",
    "redux": "^4.0.5"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "@babel/preset-typescript": "^7.10.1",
    "babel-preset-expo": "~8.1.0"
  },
  "private": true
}

【问题讨论】:

  • 是什么让你认为 Babel 被调用了?
  • 如果我没记错的话,在尝试上传 Cloud Functions 时,它需要一个调用 Babel 的构建。我在这个问题上读到的所有内容都表明它源于 Javascript 编译器(我见过很多人对 Jest 有这个问题)。声明 const warnedKeys: { [string]: boolean } = {}; 没有任何问题,它只是 Typescript,所以将 Typescript 转换为 Javascript 似乎是个问题

标签: javascript typescript firebase expo babeljs


【解决方案1】:

发现问题。这是当您尝试在 node.js 中使用 require('react-native') 时引发的错误。删除此语句解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-27
    • 2020-05-29
    • 2022-07-03
    • 1970-01-01
    • 2021-12-18
    • 2020-10-13
    相关资源
    最近更新 更多