简体   繁体   中英

Babel not converting TypeScript in Expo

I'm trying to upload Cloud Functions to my Firebase console. My app runs fine on Expo but when attempting to upload, I think my code tries compiling and throws this error:

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)

This seems to be an issue with Babel not recognizing typescript and converting it to javascript but I'm not sure how to fix it. I tried installing @babel/plugin-transform-typescript and @babel/preset-typescript separately but neither worked. Does anyone know how to fix this?

Relevant Files

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
}

Found the problem. This is an error thrown when you attempt to require('react-native') in node. Removing this statement fixed the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM