【问题标题】:React Native - unable to solve module - even if path is correctReact Native - 无法解决模块 - 即使路径正确
【发布时间】:2020-03-26 20:24:29
【问题描述】:

所以我尝试在 React Native 的 javascript 代码中使用一些图像。这是我的文件夹: enter image description here

只要我尝试使用以下命令导入它:

import React from 'react';
import { Image, StyleSheet, View } from 'react-native';
import { SimpleAnimation } from 'react-native-simple-animations';
//here i try to import my picture
import iconBright from 'testproject/pictures/iconBright.png';


export default function Welcome() {
  return (
    <View style={styles.container}>
    <SimpleAnimation delay={500} duration={1000} fade staticType='zoom'>
     //also here i am trying to import it but same error
    <Image source={require('testproject/pictures/iconBright.png')}></Image>
    </SimpleAnimation>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {

  },
});

当我编译它时,我总是得到这个错误:

Unable to resolve "pictures/iconBright.png" from "screens\Welcome.js"

我从互联网和其他 stackoverlow 建议中尝试了许多不同的方法,但都没有奏效。我也试过了:

  • ./pictures/iconBright.png
  • ../pictures/iconBright.png

但是没有任何效果。有人可以帮助我或解释一下这个路径系统是如何工作的,因为我还没有找到任何有用的指南。

编辑: 这里是设备上的错误:

Unable to resolve module `../pictures/iconBright.PNG` from `screens\Welcome.js`: 

None of these files exist:
  * pictures\iconBright.PNG(.native|.ios.expo.ts|.native.expo.ts|.expo.ts|.ios.expo.tsx|.native.expo.tsx|.expo.tsx|.ios.expo.js|.native.expo.js|.expo.js|.ios.expo.jsx|.native.expo.jsx|.expo.jsx|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json|.ios.wasm|.native.wasm|.wasm)
  * pictures\iconBright.PNG\index(.native|.ios.expo.ts|.native.expo.ts|.expo.ts|.ios.expo.tsx|.native.expo.tsx|.expo.tsx|.ios.expo.js|.native.expo.js|.expo.js|.ios.expo.jsx|.native.expo.jsx|.expo.jsx|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json|.ios.wasm|.native.wasm|.wasm)

【问题讨论】:

    标签: javascript react-native path


    【解决方案1】:

    您的图片大写为 .PNG,导入时为 .png

    我会将图像重命名为 .png 并尝试

    【讨论】:

    • 您好!我试过但不幸的是它没有解决它:(
    • 你试过这样source={require('../pictures/iconBright.PNG')}&gt;
    • 是的,但仍然是错误。我复制了 wohle 并将其添加到我的帖子中。也许会有所帮助
    • 用这个方法试过source={{uri:'your_path'}}&gt;
    • 非常感谢我不再收​​到错误消息,但我看不到图片。如果我显示文本并保存它而不是文本出现,但我看不到图片。你知道是什么问题吗?
    猜你喜欢
    • 1970-01-01
    • 2019-06-30
    • 1970-01-01
    • 2020-06-07
    • 2018-08-14
    • 2019-11-26
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    相关资源
    最近更新 更多