React Native问题集合

1.Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it’s defined in, or you might have mixed up default and named imports.

少了export default class

2.The development server returned response error code: 500

语法错误

3.

ReferenceError: Can’t find variable: View

没有引用模块

4.TypeError: undefined is not a function (evaluating ‘this.renderItem()’)

5.注释无作用?

Unexpected token ‘;’ (http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:85772)

Unexpected token ‘;’ (http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:85772)

6.reload,hot reload 有时无效。需要重新run

7.Application viewdemo has not been registered.

Hint: This error often happens when you’re running the packager (local dev server) from a wrong folder. For example you have multiple apps and the packager is still running for the app you were working on before.

If this is the case, simply kill the old packager instance (e.g. close the packager terminal window) and start the packager in the correct app folder (e.g. cd into app folder and run ‘npm start’).

8.Invariant Violation: Text strings must be rendered within a <Text> component.

注释未被编译器识别?

注意可能有空格在组件外的情况,

9.undefined is not an object (evaluating ‘scrollerView.scrollTo’)

The development server returned response error code: 500

10.undefined is not an object (evaluating ‘RootComponent.prototype’)

renderApplication

import { Navigate } from ‘./Navigate’;  括号问题。

11.图片填不满scrollview布局

1.图片大小问题,

2.resizemode属性

3.在滚动的时候把width适当增加一些(+8)

4. (虚拟机上测试无效)    layout_height=”match_parent”

                            fillViewport=”true”

12.引号怎么表示?

13.<Image source={{uri: ‘mipmap/img_1’}}

这种方式加载图片时,用flex:1无效

必须指定宽高才有效。。

14.android studio:无法格式化js

        1.import CSS & JavaScript file types:https://github.com/manifestinteractive/android-studio-filetypes.

        2.installed JS toolbox plugin.

15.does not exist in the Haste module map  

解决方案:在项目中的模块是软连接建立的,删除软连接,把模块目录复制过来后运行正常。

以下是网络上其它解决方案,未全部尝试,以上不能解决可尝试。

注意:不要使用 cnpm!cnpm 安装的模块路径比较奇怪,packager 不能正常识别!

1.Ran into this too withbabel-plugin-dotenv-import(which is very similar to react-native-dotenv). The solution is toimport all dotenv defines in a single fileand then ignore that file for coverage:

    “coveragePathIgnorePatterns”: 

        [“/node_modules/”

        ,”/src/utils/env.js”],

2.https://blog.csdn.net/u010127332/article/details/83622209

3.Move into your Project folder :

        1.rm -rf node_modules

        2.npm install

        3.Insidepackage.json. Check if all the modules are present.

        4.react-native start –reset-cache

4.I had the same issue and resolved it by adding react-native-dotenv plugin to .babelrc

“presets”: [ “react-native”, “module:react-native-dotenv” ]

 and importing vars via:

import {VAR1,VAR2} from ‘react-native-dotenv’;

5.I had similar problem – what helped was running npm start — –reset-cache command.

6.npm add @babel/runtime work for me.

7.Seeing this issue when upgrading to RN 0.57. I’ve tried all suggestions and nothing worked for me. In the end I switched to react-native-config, it’s slightly more annoying to setup but it works with the same .env files

16.Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it’s defined in, or you might have mixed up default and named imports.

类文件修改:export  default

17. TypeError: undefined is not an object (evaluating ‘_reactNative.NativeModules.UIManager.RCTVideo.Constants’)

18.Invariant Violation: requireNativeComponent: “BVLinearGradient” was not found in the UIManager.

安装模块后,要link: react-native link react-native-button-component

18.Cannot find module ‘asap/raw’

19.npm添加其它包时,各种找不到文件。报错。

npm ERR! path D:\React_Native_Project\NativeBase-KitchenSink-master\node_modules\.staging\react-native-vector-icons-1b37ab4d\node_modules\is-fullwidth-code-point

npm ERR! code ENOENT

npm ERR! errno -4058

npm ERR! syscall rename

npm ERR! enoent ENOENT: no such file or directory, rename ‘D:\React_Native_Project\NativeBase-KitchenSink-master\node_modules\.staging\react-native-vector-icons-1b37ab4d\node_modules\is-fullwidth-code-point’ -> ‘D:\React_Native_Project\NativeBase-KitchenSink-master\node_modules\.staging\is-fullwidth-code-point-62fb003f’

npm ERR! enoent This is related to npm not being able to find a file.

npm ERR! enoent

换yarn或者其他 包管理器试试。

20.> Task :app:installDebug FAILED

Skipping device ‘2230e2fc – 7.0’ for ‘app:debug’: Could not find build of variant which supports density -1 and an ABI in

开关开发者模式,开关usb调试.,撤销usb授权,重启机器. 

21.

Skipping device ‘2230e2fc’ for ‘app:debug’: Unknown API Level

项目的sdk版本与手机android版本不匹配.

开关开发者模式,开关usb调试.,撤销usb授权,重启机器. 

22.FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed – JavaScript heap out of memory

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory

经过搜索,最后的解决方案是删除npmrc文件(不是nodejs安装目录npm模块下的那个npmrc文件,而是C:\Users\{账户}\下的.npmrc文件)。

23.Failed to find target with hash string ’28’ in: D:\AndroidSDK

gradle版本引起,在build.gradle(两个)中检查几个参数版本解决.

24.

Unable to install D:\glen\RNAnimationDemo\android\app\build\outputs\apk\debug\app-debug.apk

com.android.ddmlib.InstallException

25.Error: EPERM: operation not permitted, lstat ‘D:\glen\RNAnimationDemo\android\app\build\intermediates\assets\debug\fonts’

26.Could not merge source set folders:

27.undefined is not an object

( evaluating props.sections.reduce.)

28.

“`

Could not resolve all files for configuration ‘:app:debugCompileClasspath’.

> Could not resolve com.facebook.react:react-native:+.

  Required by:

      project :app

  > Could not resolve com.facebook.react:react-native:+.

      > Failed to list versions for com.facebook.react:react-native.

        > Unable to load Maven meta-data from https://jcenter.bintray.com/com/facebook/react/react-native/maven-metadata.xml.

            > Could not HEAD ‘https://jcenter.bintray.com/com/facebook/react/react-native/maven-metadata.xml’. Received status code 502 from server: Bad Gateway

“`

29. Error while updating property ‘width’ in shadow node of type :RCTTEXT

30.can not perform a react state update on an unmounted component this is a no-op, but it indicated a memory leak in your application.

31.error An unexpected error occurred: “unsure how to copy this: /Users/betadmin/Library/Application Support/Code/1.34.0-main.sock”.

删除lock文件,再yarn

32.react native String does not match the pattern of “^(?:@[a-z0-9-~][a-z0-9-._

包名只能小写..

33.模拟器上运行没问题,真机直接崩溃,

重新初始化项目,拷贝代码重建. react native 版本和react 版本最好都保持一致

#####精彩稍后继续,尽请点赞打赏.

    原文作者:glenlg
    原文地址: https://www.jianshu.com/p/242b499cb113
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞