Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"You require appropriate loaders", Using react native and expo. App fails to compile on the web, but runs on android

I'm using react native expo. The app works fine on android, but when run on the web gets a compilation error. It was working fine in before, but I suspect this started after installing some new package.

/ReactNativeFrontend/node_modules/@codler/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js 13:12
Module parse failed: Unexpected token (13:12)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| } from 'react-native'
| import { isIphoneX } from 'react-native-iphone-x-helper'
> import type { KeyboardAwareInterface } from './KeyboardAwareInterface'
| 
| const _KAM_DEFAULT_TAB_BAR_HEIGHT: number = isIphoneX() ? 83 : 49

My babel config

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
  };
};

My package.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@codler/native-base": "^2.14.2",
    "@material-ui/core": "^4.11.0",
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/async-storage": "^1.11.0",
    "@react-native-community/datetimepicker": "^2.4.0",
    "@react-native-community/masked-view": "0.1.10",
    "@react-native-community/voice": "^1.1.6",
    "@risingstack/react-easy-state": "^6.3.0",
    "axios": "^0.19.2",
    "easy-peasy": "^3.3.1",
    "expo": "~38.0.8",
    "expo-camera": "^8.3.1",
    "expo-constants": "^9.1.1",
    "expo-font": "~8.2.1",
    "expo-gl": "^8.3.1",
    "expo-image-picker": "^8.3.0",
    "expo-permissions": "^9.0.1",
    "expo-pixi": "^1.2.0",
    "expo-speech": "~8.2.1",
    "expo-status-bar": "^1.0.2",
    "i18n-js": "^3.7.1",
    "lodash.memoize": "^4.1.2",
    "native-base": "^2.13.12",
    "proxy": "^1.0.2",
    "react": "~16.11.0",
    "react-dom": "~16.11.0",
    "react-instantsearch-native": "^6.7.0",
    "react-native-chatbot": "0.0.1-alpha.12",
    "react-native-datepicker": "^1.7.2",
    "react-native-dialogflow": "^3.2.2",
    "react-native-elements": "^2.0.4",
    "react-native-fade-in-view": "^1.1.0",
    "react-native-gesture-handler": "~1.6.0",
    "react-native-gifted-chat": "^0.16.3",
    "react-native-localization": "^2.1.6",
    "react-native-localize": "^1.4.1",
    "react-native-no-flicker-image": "^1.0.2",
    "react-native-paper": "^4.0.1",
    "react-native-reanimated": "~1.9.0",
    "react-native-safe-area-context": "~3.0.7",
    "react-native-screens": "~2.9.0",
    "react-native-signature-capture": "^0.4.10",
    "react-native-star-rating": "^1.1.0",
    "react-native-vector-icons": "^7.0.0",
    "react-native-voice": "^0.3.0",
    "react-native-web": "~0.11.7",
    "react-navigation": "^4.4.0",
    "react-navigation-stack": "^2.8.2",
    "react-navigation-tabs": "^2.9.0",
    "styled-components": "^5.1.1"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "@babel/preset-env": "^7.11.0",
    "babel-preset-expo": "~8.1.0",
    "react-native": "^0.63.2"
  },
  "private": true,
  "rnpm": {
    "assets": "./assets/fonts"
  },
  "proxy": "http://localhost:19002"
}

How to add appropriate loaders, or identify the package causing this issue.

like image 230
jackson jose Avatar asked Aug 02 '20 06:08

jackson jose


People also ask

Does Expo Use react native Web?

Expo is a framework and a platform for universal React applications. Expo for Web uses React Native for Web, provides additional cross-platform APIs, includes web build optimizations, and is compatible with the broader React Native ecosystem.

Does Expo compile to native code?

Expo app is as native as React native. They do the following things so you don't need to setup Android / iOS SDK locally. so you can build the js code and use Expo App to debug during the development. once you run expo build command, expo will upload the compiled js code and build Android/iOS file on their server.

What does Expo add to react native?

Expo is a bundle of tools created around React Native to help you start an app very fast. It provides you with a list of tools that simplify the creation and testing of React Native app. It equips you with the components of the user interface and services.


2 Answers

I had this exact same issue, I found a solution today. Thanks to this kind user on the expo forums.

judipuak's post

  1. Install the react-native-keyboard-aware-scroll-view package into your node_modules with yarn on npm
  2. Navigate to native base/dist/src/basic and open Content.js
  3. Find var _reactNativeKeyboardAwareScrollView=require('@codler/react-native-keyboard-aware-scroll-view')
  4. Change this to var _reactNativeKeyboardAwareScrollView=require('react-native-keyboard-aware-scroll-view') (remove the @codler)

Update: Here's a more permanent solution courtesy of patarapolw

I downgrade two things, and upgrade one thing, in package.json

 {
  "dependencies": {
    "native-base": "~2.11",
    "react-native-web": "~0.11"
  },
  "resolutions": {
    "react-native-keyboard-aware-scroll-view": "^0.9.0"
  },
}
like image 140
William Allen Avatar answered Oct 26 '22 22:10

William Allen


This is a native-base library problem. While You are using it's some Components there might error occur. I found that this error is not occurring in 2.11 or it's less version so try to install that specific version

npm install [email protected]
like image 38
Shivam Modi Avatar answered Oct 26 '22 23:10

Shivam Modi