0

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'
6
  • 1
    check back the path to styles.css from current file's directory path. Commented Jul 2, 2018 at 11:30
  • 1
    You have to write .. to go up one directory. Have you tried ../styles.css? Commented Jul 2, 2018 at 11:30
  • 1
    Maybe: import '../yourFileName.css'; Commented Jul 2, 2018 at 11:30
  • 1
    Thanks @Tholle it worked Commented Jul 2, 2018 at 11:31
  • 1
    If your styles.css correspond to this path 'C:\Users\Iruene Adokiye\app-react\src\styles.css' so, you must import with "../../styles.css" in LoginComponent.js file. Commented Jul 2, 2018 at 11:34

2 Answers 2

1

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`;
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.