【问题标题】:react-native package itself throws babel errorreact-native 包本身抛出 babel 错误
【发布时间】:2021-02-16 12:49:57
【问题描述】:

我正在尝试构建一个简单的 react-native 应用程序,并且我已经安装了所有依赖项。 这是我的 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';

错误显示在 type of 之后,并且显示在所有行中。 显示的错误是

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 中正确获取的。 任何帮助将不胜感激。

【问题讨论】:

    标签: reactjs react-native babeljs


    【解决方案1】:

    这是使用 Flow 语法,您尚未启用。将'@babel/flow' 添加到 Babel 预设中。

    【讨论】:

      猜你喜欢
      • 2020-04-06
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      • 2016-09-18
      • 2016-03-29
      • 2020-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多