react-native包本身抛出Babel错误



我试图建立一个简单的反应原生应用程序,我已经安装了所有的依赖关系。这是我的webpack配置文件

module: {
rules: [
{
test: /.js?$/,
// exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: {
presets: [["@babel/preset-env"], ["@babel/preset-react"],[
require.resolve('babel-preset-react-app/dependencies'),
{ helpers: true },
]],
"plugins": [
[

"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
]
}
}
}
],
},
const commonResolveBlock = {
alias: {
/**
* When using react-native-web, this statement tells webpack to resolve react-native to react-native-web at all the
* places inside your application.
*/

//"react-native$": "react-native-web",
'react-native': path.join(__dirname, 'node_modules/react-native'),
},
};

当我尝试编译相同的babel时,在node_modules中的react-native包中抛出错误(当你安装react-native时下载的那个)

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';

错误显示在类型之后,并且显示在所有行中。错误显示为

ERROR in ./node_modules/react-native/index.js
Module build failed (from /Volumes/workplace/SudhirsmUIDev/node_modules/babel-loader/lib/index.js):
SyntaxError: /Volumes/workplace/SudhirsmUIDev/src/ECAPPExperimentalHEXReactAssets/node_modules/react-native/index.js: Unexpected token, expected "{" (13:7)
11 | 'use strict';
12 | 
> 13 | import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';
|        ^
14 | import typeof ActivityIndicator from './Libraries/Components/ActivityIndicator/ActivityIndicator';
15 | import typeof Button from './Libraries/Components/Button';
16 | import typeof CheckBox from './Libraries/Components/CheckBox/CheckBox';
at Object._raise (/Volumes/workplace/SudhirsmUIDev/node_modules/@babel/parser/src/parser/error.js:60:45)
在代码中,模块是从/user/library/caches中导入的,而其他模块则是从node_modules中正确导入的。如有任何帮助,不胜感激。

这是使用流语法,您没有启用。添加'@babel/flow'到Babel预设

最新更新