【发布时间】:2021-01-21 07:30:18
【问题描述】:
我正在使用 typescript 构建一个 react-native 应用程序,以便学习 react native。一旦我使用 expo start 运行应用程序并尝试在模拟器上运行,我会收到此错误:
index.js: [BABEL] ......../index.js: Unknown option: .name. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options
其实我之前没有这个错误。我尝试安装react-native-dotenv 软件包,同时安装了metro-react-native-babel-preset,我不确定是否已经安装。
我的 package.json 如下:
{
"name": "mobile-app",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"@react-native-community/async-storage": "^1.12.0",
"@react-native-community/google-signin": "^4.0.3",
"@types/axios": "^0.14.0",
"axios": "^0.20.0",
"expo": "^38.0.10",
"react": "16.13.1",
"react-native": "0.62.2"
},
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/runtime": "^7.8.4",
"@react-native-community/eslint-config": "^1.1.0",
"@types/jest": "^25.2.3",
"@types/react-native": "^0.63.2",
"@types/react-native-dotenv": "^0.2.0",
"@types/react-test-renderer": "^16.9.2",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"babel-jest": "^25.1.0",
"eslint": "^6.5.1",
"jest": "^25.1.0",
"react-native-clean-project": "^3.4.0",
"react-native-dotenv": "^2.4.1",
"react-test-renderer": "16.13.1",
"typescript": "^3.8.3"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
}
babel.config.js:
module.exports = {
presets: ['module:metro-react-native-babel-preset', 'module:react-native-dotenv'],
};
index.js
/**
* @format
*/
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
AppRegistry.registerComponent('main', () => App);
【问题讨论】:
标签: javascript typescript react-native babeljs metro-bundler