我试图将SearchBar添加到我的react-native项目中,但一旦我添加导入,它就失败了,说Module not found:Can 't resolve 'react'沿着一堆其他模块。我已经尝试删除node_modules和package-lock.json,然后npm install,但它无法解决问题。我已经包含了js文件,package.json和我得到的错误的一部分
{
"name": "gympedia",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "expo start --dev-client",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web"
},
"dependencies": {
"@rneui/base": "^4.0.0-rc.5",
"@rneui/themed": "^4.0.0-rc.5",
"expo": "~45.0.0",
"expo-splash-screen": "~0.15.1",
"expo-status-bar": "~1.3.0",
"react": "^17.0.2",
"react-dom": "17.0.2",
"react-native": "0.68.2",
"react-native-web": "^0.17.7"
},
"devDependencies": {
"@babel/core": "^7.12.9"
},
"private": true
}
字符串
import { View, Text , Image, StyleSheet, TouchableOpacity } from 'react-native'
import React from 'react'
import { SearchBar } from "@rneui/themed";
const Header = () => {
return (
<View style={styles.container}>
<TouchableOpacity>
<Image style={styles.logo} source={require('../../assets/muscle-icon.png')} />
</TouchableOpacity>
<View style={styles.iconContainer}>
<TouchableOpacity>
<Image style={styles.icons} source={require('../../assets/search-icon.png')} />
</TouchableOpacity>
<TouchableOpacity>
<Image style={styles.icons} source={require('../../assets/bookmark-icon.png')}/>
</TouchableOpacity>
</View>
</View>
)
}
型
Module not found: Can't resolve 'react'
> 1 | import { useMemo } from 'react';
2 | import { StyleSheet } from 'react-native';
3 | export const makeStyles = (styles) => (props) => {
4 | return useMemo(() => {
../node_modules/@rneui/themed/dist/config/makeStyles.js:1
Module not found: Can't resolve 'react'
> 1 | import { useMemo } from 'react';
2 | import { StyleSheet } from 'react-native';
3 | import { useTheme } from './ThemeProvider';
4 | export const makeStyles = (styles) => (props = {}) => {
../node_modules/@rneui/base/dist/helpers/index.js:1
Module not found: Can't resolve 'react-native'
> 1 | import { Platform, Dimensions } from 'react-native';
2 | import color from 'color';
3 | import renderNode from './renderNode';
4 | import getIconType, { registerCustomIconType } from './getIconType';
../node_modules/@rneui/base/dist/helpers/colors.js:1
Module not found: Can't resolve 'react-native'
> 1 | import { StyleSheet } from 'react-native';
2 | export const lightColors = {
3 | primary: '#2089dc',
4 | secondary: '#03dac4',
型
2条答案
按热度按时间rqmkfv5c1#
看起来这可能是@rneui库的问题。我会尝试将这两个库降级到以前的版本。只需查看下一个以前版本的库并执行npm install @rneui/base@version# @reneui/themed@version#。也可能是你在两个导入的末尾没有分号。
mlnl4t2r2#
当我们导入一些模块/依赖项在我们的代码中使用时(通过
npm/yarn install
),依赖项的条目是在package.json
文件中创建的。所以当我们使用它们时,它们将被引用。类似地,我们导入的许多模块在内部处理其代码时进一步依赖于其他模块。因此,以同样的方式,每个模块都有自己的
package.json
文件。似乎错误中提到的模块条目在模块
package.json
文件中没有提到。解决这个问题
project_directory/node_modules/{your_module_name}/
中存在的package.json
文件中的问题。在“添加"devDependencies"
”部分中,添加您的模块及其所使用的缺失的版本沿着。如果需要,请添加keyword
条目