簡體   English   中英

Babel 沒有在 Expo 中轉換 TypeScript

[英]Babel not converting TypeScript in Expo

我正在嘗試將 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 無法識別 typescript 並將其轉換為 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
}

發現了問題。 這是當您嘗試在 node.js 中使用 require('react-native') 時引發的錯誤。 刪除此語句解決了問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM