[英]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.