【问题标题】:React Native Cannot assign to read only property 'exports' of objectReact Native 无法分配给对象的只读属性“exports”
【发布时间】:2020-06-26 05:10:54
【问题描述】:

我在 coursera 中学习 React Native。我跟随老师的每一步,但不知何故,编写的代码在他的机器上工作。但是与我在计算机中实现的完全相同的代码显示了以下错误。我在 chrome 浏览器中运行这段代码。我成功安装了 Expo。

bundle.js:78667 Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
    at Module.<anonymous> (bundle.js:78667)
    at Module.E:\WORKING PROJECT\coursera\courserReactNat\node_modules\react-native-elements\src\helpers\normalizeText.js (bundle.js:78668)
    at __webpack_require__ (bundle.js:727)
    at fn (bundle.js:101)
    at Module.E:\WORKING PROJECT\coursera\courserReactNat\node_modules\react-native-elements\src\helpers\index.js (bundle.js:78556)
    at __webpack_require__ (bundle.js:727)
    at fn (bundle.js:101)
    at Module.<anonymous> (bundle.js:76709)
    at Module.E:\WORKING PROJECT\coursera\courserReactNat\node_modules\react-native-elements\src\buttons\Button.js (bundle.js:76965)
    at __webpack_require__ (bundle.js:727)
    at fn (bundle.js:101)
    at Module.E:\WORKING PROJECT\coursera\courserReactNat\node_modules\react-native-elements\src\index.js (bundle.js:79112)
    at __webpack_require__ (bundle.js:727)
    at fn (bundle.js:101)
    at Module.E:\WORKING PROJECT\coursera\courserReactNat\components\MenuComponent.js (bundle.js:12291)
    at __webpack_require__ (bundle.js:727)
    at fn (bundle.js:101)
    at Module.E:\WORKING PROJECT\coursera\courserReactNat\components\mainComponent.js (bundle.js:12356)
    at __webpack_require__ (bundle.js:727)
    at fn (bundle.js:101)
    at Module.E:\WORKING PROJECT\coursera\courserReactNat\App.js (bundle.js:12263)
    at __webpack_require__ (bundle.js:727)
    at fn (bundle.js:101)
    at Module.E:\WORKING PROJECT\coursera\courserReactNat\node_modules\expo\AppEntry.js (bundle.js:20679)
    at __webpack_require__ (bundle.js:727)
    at fn (bundle.js:101)
    at Object.0 (bundle.js:12246)
    at __webpack_require__ (bundle.js:727)
    at bundle.js:794
    at bundle.js:797

我的代码有三个类MainComponent

import React,{Component} from 'react'
import {DISHES} from '../shared/dishes'
import Menu from './MenuComponent';


class MainComponent extends Component{


    constructor(props) {
        super(props);
        this.state = {
            dishes:DISHES
        }
    }

    render() {
        return (
            <Menu dishes={this.state.dishes}/>
        );
    }
}
export default MainComponent;

菜单

import React from 'react'
import {View,FlatList} from 'react-native'
import  {ListItem} from 'react-native-elements'



function Menu(props) {

    const renderMenuItem = ({item,index}) =>{
        return(
            <ListItem
                key={index}
                title={item.name}
                subtitle={item.description}
                hideChevron={true}
                leftAvatar={{source:require('../shared/images/uthappizza.png')}}
            />
        );
    }

    return(
        <FlatList
           data={props.dishes}
           renderItem={renderMenuItem}
           keyExtractor={item => item.id.toString()}
          />
    )
}

export default Menu;

应用类

import React from 'react';
import Main from "./components/mainComponent";

export default function App() {
  return (
    <Main />
  );
}

这里可能有什么问题,我被困住了。不知道如何解决这个问题。提前致谢

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    嘿嘿!我也在做同样的课程,并且遇到了同样的错误。问题是您无法在给定here 的 Web 浏览器上运行 React Native 应用程序。据我所知,运行 React Native 应用程序的一种方法是在您的 Android/IOS 设备上安装 Expo 应用程序并使用 Expo 应用程序扫描 QR 码。我面临的第二个问题是 Expo 应用程序中的“未捕获的错误:Packager 未在 http://192.168.0.100.19001 运行”,然后通过将 PC/笔记本电脑和 Andoid/IOS 设备连接到相同的 LAN 连接来解决。

    【讨论】:

      猜你喜欢
      • 2019-04-27
      • 1970-01-01
      • 2021-09-26
      • 2019-11-28
      • 2019-06-13
      • 2021-07-25
      • 2019-12-09
      • 2021-12-04
      • 1970-01-01
      相关资源
      最近更新 更多