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

喜夏-厌秋 提交于 2021-02-08 13:27:09

问题


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.


回答1:


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"
  },
}



回答2:


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 native-base@2.11


来源:https://stackoverflow.com/questions/63213100/you-require-appropriate-loaders-using-react-native-and-expo-app-fails-to-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!