我正在从 react-native 中获取 The module `./index.css` could not be found

I am getting The module `./index.css` could not be found From react-native

我正在从 react-native 中找到模块 ./index.css

我已经正确导入文件到该位置。在google上搜索了很多,请帮忙

这里是错误的完整输出,

Body:
{"originModulePath":"/Users/tejas-mac/Documents/React Studio/Exported Projects/index.js","targetModuleName":"./index.css","message":"Unable to resolve module `./index.css` from `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.js`: The module `./index.css` could not be found from `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.js`. Indeed, none of these files exist:\n\n  * `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.css(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)`\n  * `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.css/index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)`","errors":[{"description":"Unable to resolve module `./index.css` from `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.js`: The module `./index.css` could not be found from `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.js`. Indeed, none of these files exist:\n\n  * `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.css(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)`\n  * `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.css/index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)`"}],"name":"Error","stack":"Error: Unable to resolve module `./index.css` from `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.js`: The module `./index.css` could not be found from `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.js`. Indeed, none of these files exist:\n\n  * `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.css(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)`\n  * `/Users/tejas-mac/Documents/React Studio/Exported Projects/index.css/index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)`\n    at ModuleResolver.resolveDependency (/Users/tejas-mac/Documents/React Studio/Exported Projects/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:161:851)\n    at ResolutionRequest.resolveDependency (/Users/tejas-mac/Documents/React Studio/Exported Projects/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:91:16)\n    at DependencyGraph.resolveDependency (/Users/tejas-mac/Documents/React Studio/Exported Projects/node_modules/metro/src/node-haste/DependencyGraph.js:272:4579)\n    at dependencies.map.relativePath (/Users/tejas-mac/Documents/React Studio/Exported Projects/node_modules/metro/src/DeltaBundler/traverseDependencies.js:376:19)\n    at Array.map (<anonymous>)\n    at resolveDependencies (/Users/tejas-mac/Documents/React Studio/Exported Projects/node_modules/metro/src/DeltaBundler/traverseDependencies.js:374:16)\n    at /Users/tejas-mac/Documents/React Studio/Exported Projects/node_modules/metro/src/DeltaBundler/traverseDependencies.js:212:33\n    at Generator.next (<anonymous>)\n    at step (/Users/tejas-mac/Documents/React Studio/Exported Projects/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:313)\n    at /Users/tejas-mac/Documents/React Studio/Exported Projects/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:473"}
processBundleResult
    BundleDownloader.java:266
access0
    BundleDownloader.java:35
onResponse
    BundleDownloader.java:153
execute
    RealCall.java:135
run
    NamedRunnable.java:32
runWorker
    ThreadPoolExecutor.java:1133
run
    ThreadPoolExecutor.java:607
run
    Thread.java:761

根据 React Native 文档:

您没有使用特殊的语言或语法来定义样式。您只需使用 JavaScript 设置您的应用程序的样式。所有核心组件都接受一个名为 style 的道具。样式名称和值通常与 CSS 在 Web 上的工作方式相匹配,但名称使用驼峰式大小写,例如 backgroundColor 而不是 background-color

style 道具可以是一个普通的旧 JavaScript 对象。

随着组件越来越复杂,使用 StyleSheet.create 在一个地方定义多个样式通常会更简洁。这是一个例子:

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class LotsOfStyles extends Component {
  render() {
    return (
      <View>
        <Text style={styles.red}>just red</Text>
        <Text style={styles.bigblue}>just bigblue</Text>
        <Text style={[styles.bigblue, styles.red]}>bigblue, then red</Text>
        <Text style={[styles.red, styles.bigblue]}>red, then bigblue</Text>
      </View>
    );
   }
 }

const styles = StyleSheet.create({
  bigblue: {
    color: 'blue',
    fontWeight: 'bold',
    fontSize: 30,
  },
  red: {
    color: 'red',
  },
});

当然,样式不需要与组件位于同一个文件中。您可以将它们抽象到一个单独的文件中,然后简单地从那里导出它们并在需要的地方导入。