在Expo中,需要模块“提取",引发了异常:ReferenceError:找不到变量:self [英] In Expo, Requiring module "fetch", threw an exception: ReferenceError: Can't find variable: self

查看:107
本文介绍了在Expo中,需要模块“提取",引发了异常:ReferenceError:找不到变量:self的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了各种可能的答案,但没有找到解决此特定错误的合适方法.

I have searched across different possible answers, but didn't find any appropriate addressing this specific error.

我在问题标题中提到了确切的错误字符串.当我在ReactNative应用程序中安装fetch npm模块时,开始出现此错误.该错误仅在开发过程中在手机上启动/加载应用程序时出现.在安装fetch之前,我的应用已正确加载到手机上.在Windows CLI中,没有这样的错误可以帮助我解决问题,只是表明构建成功.

I have mentioned the exact error string in the question title. This error started appearing when I installed fetch npm module in my ReactNative app. This error appears just at the time app is launched/loaded on my phone during development. Before installing fetch, my app was loading correctly on the phone. In windows CLI there is no such error that assist me to resolve the issue, it just shows the build is successful.

我正在使用Expo进行我的ReactNative应用程序开发.请协助解决此问题.可以在下面的附加屏幕(显示堆栈跟踪)中看到更多详细信息:

I am using Expo for my ReactNative app development. Please assist in this regard to resolve the issue. Further details can be seen in following attached screen (that shows stack trace):

Package.json

{
    "name": "my-new-project",
    "main": "node_modules/expo/AppEntry.js",
    "private": true,
    "scripts": {
        "start": "expo start",
        "android": "expo start --android",
        "ios": "expo start --ios",
        "eject": "expo eject",
        "test": "node ./node_modules/jest/bin/jest.js --watchAll"
    },
    "jest": {
        "preset": "jest-expo"
    },
    "dependencies": {
        "@expo/samples": "2.1.1",
        "expo": "29.0.0",
        "fetch": "^1.1.0",
        "react": "16.3.1",
        "react-native": "https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz",
        "react-navigation": "^2.9.3"
    },
    "devDependencies": {
        "jest-expo": "29.0.0"
    }
}

这是一个很奇怪的问题,当我卸载 fetch并尝试使用任何其他库时,例如axios,仍然出现对相同错误的引用(与访存模块有关).我已经重新启动了笔记本电脑,还重新启动了移动设备上的Expo应用程序.

This is a quite strange issue, that when I Uninstall fetch and try to use any other library e.g. axios, the reference to same error (related to fetch module) still appears. I have restarted my laptop machine, and restarted Expo app on mobile as well.

推荐答案

我已经弄清楚了,基本上不是npm还是 NPM fetch组件问题.基本上,在设置项目后,我运行了npm install expo-cli,当我尝试运行expo startnpm start时,该消息出现在CLI中.目前,有v30.x.x可用的新版本,是的self参考问题在较早的expo版本中,但没有在v30.x.x中.

I have figured it out, basically it was not the npm neither the NPM fetch component issue. Basically after setting up the project I ran npm install expo-cli which message was appearing in CLI when I try to run expo start or npm start. At this time there was new version available v30.x.x, and YES the self reference issue was in older expo version but not in v30.x.x.

安装expo-cli后,它与我现有的项目expo配置和安装的文件都不匹配,因此我再次重新设置了该项目,该项目加载并安装了最新版本的库,并将项目文件复制到其中.

After installing expo-cli it was not matching to my existing project expo configuration and installed files, hence I re-setup the project again, which loaded and installed latest version libraries and coppied the project files into it.

繁荣!这次应用程序运行没有任何错误.

And boom! The application ran without any error this time.

这篇关于在Expo中,需要模块“提取",引发了异常:ReferenceError:找不到变量:self的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆