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

泄露秘密 提交于 2019-12-11 18:27:56

问题


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

I have imported the file correctly on the location. Searched a lot on the google , please help.

Here is the full output of the error,

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
access$200
    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

回答1:


According to the React Native Documentation:

You don't use a special language or syntax for defining styles. You just style your application using JavaScript. All of the core components accept a prop named style. The style names and values usually match how CSS works on the web, except names are written using camel casing, e.g backgroundColor rather than background-color.

The style prop can be a plain old JavaScript object.

As a component grows in complexity, it is often cleaner to use StyleSheet.create to define several styles in one place. Here's an example:

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',
  },
});

And of course, the styles do not need to be in the same file as the component. You can abstract them to a separate file and then simply export them from there and import where needed.



来源:https://stackoverflow.com/questions/50246677/i-am-getting-the-module-index-css-could-not-be-found-from-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!