Importing css into React JS

Asked

Viewed 2,503 times

1

Good morning, I am new to React and I am trying to import a css file into my Cabecalho component, however I am not able to do this with normal import, I would like to know how to do this because it is not finding my css file, Thanks already

my css file: Aplication css style.css

this is the error that it is giving in the browser erro do browser

I took a print of my project too

inserir a descrição da imagem aqui

  • What is the Cabecalho.js folder? Notice that you are trying to take the style.css file inside this folder.

  • then Cabecalho.js is in this directory : Aplication src Components Cabecalho.js , however I had already tried to pass this path and it seems that it is not recognizing the css files

1 answer

2


The problem is, in your code, you’re saying that the file style.css is on the way aplication\src\components\, since you are importing in the following way:

import './style.css'; //Aqui diz para procurar um style.css na pasta atual

Another problem is that the webpack is configured to see the src folder as the root, so you need to put the css folder inside the src folder and replace the import with:

import '../css/style.css'; //Aqui sobe um nível (src), entra na pasta css e busca por style.css
  • I just tried but tbm n worked, it displayed the following error: . /src/Components/Cabecalho.js Module not found: You attempted to import .. /.. /css/style.css which Falls Outside of the project src/ directory. Relative Imports Outside of src/ are not supported.

  • The problem is that he only sees inside the briefcase src, then you have to put the css folder inside the src folder. I edited my answer with this.

  • worked out, thank you so much for the help !!!

  • @Giovannimanganotti if you can, please select as response, please (:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.