react-native程序包本身引发babel错误

uinbv5nw  于 2022-12-16  发布在  Babel
关注(0)|答案(1)|浏览(147)

我正在尝试构建一个简单的React原生应用程序,并且已经安装了所有依赖项。

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)

还有一个问题是react-native单独在代码中,模块是从/user/library/caches导入的,对于所有其他模块,它是从node_modules正确获取的。

a2mppw5e

a2mppw5e1#

这是使用流语法,你没有启用。添加'@babel/flow'到巴别塔预设。

相关问题