“你需要合适的加载器”,使用 react native 和 expo。应用程序无法在 web 上编译,但在 android 上运行
Posted
技术标签:
【中文标题】“你需要合适的加载器”,使用 react native 和 expo。应用程序无法在 web 上编译,但在 android 上运行【英文标题】:"You require appropriate loaders", Using react native and expo. App fails to compile on the web, but runs on android 【发布时间】:2020-11-22 13:20:18 【问题描述】:我正在使用 react native expo。该应用程序在 android 上运行良好,但在 web 上运行时会出现编译错误。它以前工作正常,但我怀疑这是在安装一些新软件包后开始的。
/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
我的 babel 配置
module.exports = function(api)
api.cache(true);
return
presets: ['babel-preset-expo'],
;
;
我的 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"
如何添加适当的加载器,或识别导致此问题的包。
【问题讨论】:
【参考方案1】:我遇到了同样的问题,我今天找到了解决方案。 感谢世博论坛上的这种好心用户。
judipuak's post
-
在 npm 上使用 yarn 将
react-native-keyboard-aware-scroll-view
包安装到你的 node_modules 中
导航到原生 base/dist/src/basic 并打开 Content.js
查找var _reactNativeKeyboardAwareScrollView=require('@codler/react-native-keyboard-aware-scroll-view')
将此更改为var _reactNativeKeyboardAwareScrollView=require('react-native-keyboard-aware-scroll-view')
(删除@codler
)
更新: 这是一个更永久的解决方案 礼貌patarapolw
我在 package.json 中降级两件事,升级一件事
"dependencies":
"native-base": "~2.11",
"react-native-web": "~0.11"
,
"resolutions":
"react-native-keyboard-aware-scroll-view": "^0.9.0"
,
【讨论】:
所以,解决方案是……不使用代码?为什么会发生这种情况。【参考方案2】:这是一个本地库问题。当您使用它的某些组件时,可能会发生错误。我发现这个错误在 2.11 中没有发生,或者它的版本较低,所以尝试安装该特定版本
npm install native-base@2.11
【讨论】:
以上是关于“你需要合适的加载器”,使用 react native 和 expo。应用程序无法在 web 上编译,但在 android 上运行的主要内容,如果未能解决你的问题,请参考以下文章