我在尝试加载我的组件时遇到错误:
Failed to load bundle(http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(Unable to resolve module
components/Items
from/Users/vemundeldegard/AwesomeProject/app/screens/Home.js
: Modulecomponents/Items
does not exist in the Haste module mapThis 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 thenode_modules
folder:rm -rf node_modules && npm install
. 3. Reset Metro Bundler cache:rm -rf /tmp/metro-bundler-cache-*
ornpm start -- --reset-cache
. 4. Remove haste cache:rm -rf /tmp/haste-map-react-native-packager-*
. (null))
尝试在名为 screens/home.js 的屏幕中加载我的组件,然后将其加载到我的 app.js 中。
将此添加到/screens/home.js 文件的顶部:
import Items from 'components/Items';
然后像这样在渲染中调用它 <Items />
components/items.js 看起来像这样:
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View
} from 'react-native';
const Items = () => {
return (
<View>This is now an item</View>
)
}
export default Items;
为什么我无法加载组件?尝试按照错误提示进行操作。
最佳答案
尝试import Items from '../components/items'
,实际上你的文件被命名为items
(没有大写i)而不是Items
.
关于javascript - 在 React Native 中加载组件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52282980/