捆绑失败:错误:插件 0 提供了无效的属性 "default"



我正试图使用以下命令在我的AVD上运行一个react原生应用程序:

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:UsersASUStestnode_modulesbabel-corelibtransformationplugin.js:131:13)
at Function.normalisePlugin (C:UsersASUStestnode_modulesbabel-corelibtransformationfileoptionsoption-manager.js:152:12)
at C:UsersASUStestnode_modulesbabel-corelibtransformationfileoptionsoption-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (C:UsersASUStestnode_modulesbabel-corelibtransformationfileoptionsoption-manager.js:158:20)
at OptionManager.mergeOptions (C:UsersASUStestnode_modulesbabel-corelibtransformationfileoptionsoption-manager.js:234:36)
at C:UsersASUStestnode_modulesbabel-corelibtransformationfileoptionsoption-manager.js:265:14
at C:UsersASUStestnode_modulesbabel-corelibtransformationfileoptionsoption-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 v8.11.3&反应天然v 0.55.4

我已经尝试了互联网上推荐的所有东西(特别是github(,但仍然没有成功。如果有人能帮忙,我真的很感激。

这是babel-preset-react-native中的错误

设置版本:

yarn remove babel-preset-react-native
yarn add babel-preset-react-native@2.1.0

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

  1. 然后通过react native run android运行应用程序

它会运行良好。。。

应该使用最新版本的jest,它可以工作 "babel-jest": "23.3.0", "babel-preset-react-native": "5.0.2", "jest": "23.3.0",

好吧,可能会迟到,但我会帮助其他人,因为下面的包.json工作到2018年8月20日

下面是package.json大多数依赖项,如axios、Redux、Native base、react Native router flux。。etc在react原生项目中使用,所以我在下面提到的版本彼此兼容。干杯

{
"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"
}
}

我遇到了这个问题,我需要降级babel-preset-react-native版本。

如果你使用纱线

yarn remove babel-preset-react-native
yarn add babel-preset-react-native@4.0.0

或使用npm命令

npm uninstall babel-preset-react-native
npm install babel-preset-react-native@4.0.0

最新更新