React Native常见报错

常见报错:Error:Cannot find module 'jest-haste-map'

Error: Cannot find module 'jest-haste-map'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

解决办法:npm install jest-haste-map --save

npm install jest-haste-map --save
npm WARN @babel/plugin-check-constants@7.0.0-beta.38 requires a peer of @babel/core@7.0.0-beta.38 but none is installed. You must install peer dependencies yourself.

+ jest-haste-map@23.4.1
added 4 packages and updated 1 package in 19.344s

Property right of AssignmentExpression expected node to be of a type ["Expression"] but instead got null

解决办法:修改package.json文件devDependencies增加,修改.babelrc文件

    "@babel/plugin-proposal-decorators": "7.0.0-beta.47",
    "babel-preset-react-native": "5.0.1",
WechatIMG816.jpeg
{
  "presets": [
    "react-native"
  ],
  "plugins": [
   ["@babel/plugin-proposal-decorators", { "legacy": true }]
  ],
  "env": {
    "production": {
      "plugins": [
        "transform-remove-console"
      ]
    }
  }
}

WX20180806-224032@2x.png

Cannot read property...

node_modules/react-native/Libraries/react-native/react-native-
implementation.js: Cannot read property 'bindings' of null (null))

解决办法:npm i babel-preset-react-native@5

Bundling index.ios.js 99.0% (405/407), failed.

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
  1. Clear watchman watches: `watchman watch-del-all`.
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
  3. Reset packager cache: `rm -fr $TMPDIR/react-*` or `npm start -- --reset-cache`.

解决办法:

watchman watch-del-all
rm -rf node_modules && npm install
npm start --reset-cache

react-native.js: Unable to find this module in its module map or any of the node_modules directories

解决办法:

npm i --save react@15.0.2

Bundling failed: Error: Unable to resolve module react-native-tab-view

解决办法:

npm i github:react-navigation/react-native-tab-view

You are currently using minified code outside of NODE_ENV === 'production'. This means that you are running a slower development build of Redux

解决办法:在RN代码里面全局查找process.env.NODE_ENV将其值设为production,可能其值现在为development。

const global_def = `(function (global) {global.__DEV__=false;global.__BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now();global.process=this.process||{};global.process.env=process.env||{};global.process.env.NODE_ENV='production';})(this);`

[React-native: Super expression must either be null or a function, not undefined]

解决办法:修改引入Component方式。

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image,
  TextInput,
  Button,
  TouchableHighlight,
} from 'react-native';
[React native: Cannot add a child that doesn't have a YogaNode or parent node(Trying to add a 'ReactRawTextShadowNode' to a 'LayoutShadowNode')]
      <View style={[styles.container]}>
      <BoxShadow setting={shadowOpt}>
                <TouchableOpacity style={{
                    position:"relative",
                    width: 160,
                    height: 170,
                    backgroundColor: "#fff",
                    borderRadius:3,
                    // marginVertical:5,
                    overflow:"hidden"}}>
                    测试
                </TouchableOpacity>
            </BoxShadow>
      </View>

解决办法:删除组件里面的含有"//"注释,删除//marginVertical:5这一行,还是报错,后来发现TouchableOpacity里面不能直接添加汉字,需要加Text。

   <BoxShadow setting={shadowOpt}>
                <TouchableOpacity style={{
                    position:"relative",
                    width: 160,
                    height: 170,
                    backgroundColor: "#fff",
                    borderRadius:3,
                    overflow:"hidden"}}>
                    <Text>测试</Text>
                </TouchableOpacity>
            </BoxShadow>

   <BoxShadow setting={shadowOpt}>
                <TouchableOpacity style={{
                    position:"relative",
                    width: 160,
                    height: 170,
                    backgroundColor: "#fff",
                    borderRadius:3,
                    overflow:"hidden"}}>
                    {!!'测试'}
                </TouchableOpacity>
            </BoxShadow>

后面这一种测试二字显示不出来,为了防止崩溃,加两个!!将"测试"取两次反,转化为BOOL防止为空。

/react-native/third-party/glog-0.3.4/src/base/mutex.h:105:10: fatal error: 'config.h' file not found #include "config.h" // to figure out pthreads support

解决办法:

Close Xcode.
cd <Project-Folder>/node_modules/react-native/third-party/glog-0.3.4
Run ./configure
Run make
Run make install
Open Xcode and try building the Project.
undefined is not an object (evaluating ‘RNGestureHandlerModule.state’)

解决办法:

remove node_modules and package-lock.json
npm install
npm install --save react-navigation
npm install --save react-native-gesture-handler
react-native link
官方给出解决方案
yarn add react-navigation
# or with npm
# npm install --save react-navigation
yarn add react-native-gesture-handler
# or with npm
# npm install --save react-native-gesture-handler
react-native link react-native-gesture-handler
06B65DD6-45DD-4699-89DB-62FA93BE2D31.png
Cannot read property 'changedBits' of undefined

解决办法:升级react-native版本,"react-native": "0.55.3",npm install。

error: bundling failed: Error: Unable to resolve module metro/src/lib/bundle-modules/HMRClient from /Users/<user-directory>/Desktop/temp/react-native/Libraries/Utilities/HMRClient.js: Module does not exist in the module map

解决办法:升级react-native版本,"react-native": "0.55.4",npm install。

unsupported top level event type "onGestureHandlerStateChange" dispatched

解决办法:降低"react-native-gesture-handler":"1.0.14",npm install。

Build input file cannot be found: 'node_modules/react-native/third-party/double-conversion-1.1.6/src/fixed-dtoa.cc'

解决办法:

$ cd node_modules/react-native/scripts && ./ios-install-third-party.sh && cd ../../../
$ cd node_modules/react-native/third-party/glog-0.3.5/ && ../../scripts/ios-configure-glog.sh && cd ../../../../
undefined is not an object (evaluating 'rngesturehandlermodule2.default.Direction')

解决办法:

Right Click Libraries "Add Files to Project"
/node_modules/react-native-gesture-handlers/ios/RNGestureHandler.xcodeproj
Go to build phases and add libRNGestureHandler.a
Run
1.gif
Client called nw_connection_get_connected_socket on unconnected nw_connection

解决办法:Edit Scheme => Run => Environment Variables => Add OS_ACTIVITY_MODE:disable in the XCode。

8.gif
npm ERR! missing script: start

解决办法:在package.json文件中增加"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
}。


QQ20190702-210019@2x.png
Connection to localhost port 8081 [tcp/sunproxyadmin] succeeded!

Port 8081 already in use, packager is either not running or not running correctly
Command PhaseScriptExecution failed with a nonzero exit code
解决办法:RN使用8081端口作为资源加载的端口,如果端口被占用,就会产生该编译错误,就算成功运行,APP也无法加载Bundler,导致红色告警页面。

sudo lsof -i:8081

查看占用该端口的应用,并找到其PID,利用命令

sudo kill <pid>

来杀死该程序。


QQ20190702-212821@2x.png
Build input file cannot be found: '/Users/cloud/Documents/RNDemo/LearnReduxProject/node_modules/react-native/Libraries/WebSocket/libfishhook.a'

解决办法:Try to switch back to the Legacy Build System (File > Project Settings > Workspace Settings > Legacy Build System)。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,080评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,422评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,630评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,554评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,662评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,856评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,014评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,752评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,212评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,541评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,687评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,347评论 4 331
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,973评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,777评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,006评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,406评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,576评论 2 349

推荐阅读更多精彩内容