【发布时间】: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