Adokiye Iruene
Adokiye Iruene

Reputation: 870

Module not found - React

I'm trying to import a css file in the previous folder,i.e src folder, before the one that the component is in but it keeps on bringing this error, Please what am I doing wrong

Failed to compile
./src/components/LoginComponent.js
Module not found: Can't resolve './src/styles.css' in 'C:\Users\Iruene     Adokiye\app-react\src\components'

Upvotes: 0

Views: 450

Answers (2)

loelsonk
loelsonk

Reputation: 3598

if your project structure is like this:

- src/
  - components/
    - LoginComponent.js
  - style.css

Then inside your LoginComponent use:

import from '../styles.css';

or named import

import styles from '../styles.css';

.. means "above" folder.

. means same folder.

Upvotes: 1

Tholle
Tholle

Reputation: 112777

To import src/styles.css from your component located at src/components/LoginComponent.js, you have to import from one directory up:

import `../styles.css`;

Upvotes: 1

Related Questions