我正在尝试使用以下命令在我的AVD上运行react native应用程序:
react-native run-android
但出现以下错误:
bundling failed: Error: Plugin 0 specified in "C:\\Users\\ASUS\\test\\node_modules\\babel-preset-react-native\\index.js" provided an invalid property of "default" (While processing preset: "C:\\Users\\ASUS\\test\\node_modules\\babel-preset-react-native\\index.js")
at Plugin.init (C:\Users\ASUS\test\node_modules\babel-core\lib\transformation\plugin.js:131:13)
at Function.normalisePlugin (C:\Users\ASUS\test\node_modules\babel-core\lib\transformation\file\options\option-manager.js:152:12)
at C:\Users\ASUS\test\node_modules\babel-core\lib\transformation\file\options\option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (C:\Users\ASUS\test\node_modules\babel-core\lib\transformation\file\options\option-manager.js:158:20)
at OptionManager.mergeOptions (C:\Users\ASUS\test\node_modules\babel-core\lib\transformation\file\options\option-manager.js:234:36)
at C:\Users\ASUS\test\node_modules\babel-core\lib\transformation\file\options\option-manager.js:265:14
at C:\Users\ASUS\test\node_modules\babel-core\lib\transformation\file\options\option-manager.js:323:22
at Array.map (<anonymous>)
.babelrc:
{
"presets": [
"react-native"
"@babel/preset-flow"
]
}
package.json:
{
"name": "test",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.4.1",
"react-native": "^0.55.4"
},
"devDependencies": {
"babel-jest": "23.4.0",
"babel-preset-react-native": "5.0.2",
"jest": "23.4.1",
"react-test-renderer": "16.4.1"
},
"jest": {
"preset": "react-native"
}
}
我正在使用Windows,node.js v 8.11.3和react native v 0.55.4
我已经尝试了互联网上推荐的所有内容(特别是github),但还是没有运气。如果有人可以帮忙,我会非常感激。
答案 0 :(得分:13)
这是<button onclick="myFunction()" class="button">Click Here to go </button>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<hr>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<hr>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<hr>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<hr>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<hr>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<hr>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<hr>
<div id="search_cont">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<hr>
设置版本:
babel-preset-react-native
答案 1 :(得分:2)
它在React native中存在一些不兼容的版本控制问题。请尝试使用它
1。更改 package.json
中的以下版本在依赖项中:-
"react": "16.3.1"
"react-native": "0.55.4"
在devDependencies中:-
"babel-preset-react-native": "2.1.0"
2。删除 node_modules 并运行 npm install --save
它将运行正常...
答案 2 :(得分:1)
应该使用Jest到最新版本,它可以工作
"babel-jest": "23.3.0",
"babel-preset-react-native": "5.0.2",
"jest": "23.3.0",
答案 3 :(得分:1)
我遇到了这个问题,我需要降级babel-preset-react-native
版本。
yarn remove babel-preset-react-native
yarn add babel-preset-react-native@4.0.0
npm uninstall babel-preset-react-native
npm install babel-preset-react-native@4.0.0
答案 4 :(得分:0)
可能已经晚了,但是我会帮助其他人,如下package.json的工作日期是2018年8月20日。
在 package.json 下面,React本机项目中使用了大多数依赖项,例如axios,Redux,Native base,react-native-router-flux ..etc,因此下面提到的版本彼此兼容。 干杯。
{
"name": "Example",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"resolutions": {
"*/@babel/cli": "7.0.0-beta.54",
"*/@babel/core": "7.0.0-beta.54",
"*/@babel/code-frame": "7.0.0-beta.54"
},
"dependencies": {
"axios": "^0.18.0",
"eslint": "^5.2.0",
"native-base": "2.6.1",
"prop-types": "^15.6.2",
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-router-flux": "^4.0.1",
"react-native-timeline-listview": "^0.2.3",
"react-navigation": "^2.11.2",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"babel-jest": "23.4.2",
"babel-preset-react-native": "4.0.0",
"jest": "23.5.0",
"react-test-renderer": "16.4.1"
},
"jest": {
"preset": "react-native"
}
}