Sudhir Somasundaram
Sudhir Somasundaram

Reputation: 21

react-native package itself throws babel error

I am trying to build a simple react-native app and I have installed all the dependencies. This is my webpack config file

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'),
  },
};

when i try to compile the same babel is throwing error in react-native package inside node_modules(The one that gets downloaded when you install 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';

the error is shown after type of and it is shown in all the lines. Error shown is

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)

one more issue for react-native alone in code the module is imported from /user/library/caches for all others it is taken properly from node_modules. Any help will be appreciated.

Upvotes: 2

Views: 537

Answers (1)

Marnanel Thurman
Marnanel Thurman

Reputation: 425

This is using Flow syntax, which you don't have enabled. Add '@babel/flow' to the Babel presets.

Upvotes: 1

Related Questions