For hours now, I've been trying to figure out how to link an external CSS file to my NavBar.js for my website. Despite several attempts at troubleshooting, I keep encountering the following error:
Module not found: Can't resolve './components/layouts/NavbarStyles.css'
I've made sure to install both css-loader and style-loader in my dependencies:
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.4.0",
"@testing-library/user-event": "^7.2.1",
"bootstrap": "^4.4.1",
"css-loader": "^3.4.0",
"react": "^16.12.0",
"react-bootstrap": "^1.0.0-beta.16",
"react-dom": "^16.12.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0"
"devDependencies": {
"style-loader": "^1.1.2"
I have also set up a module in my webpack.config.js (specifically around line 330, which may seem lengthy compared to what some tutorials show):
module: {
rules: [{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
}, ],
},
My imports:
import React from 'react'
import './components/layouts/NavbarStyles.css';
Here are my files: /src/components/layouts/NavbarStyles.css
Any suggestions or ideas on how to resolve this issue would be greatly appreciated!
Thank you!
EDIT: I made changes to the imports in my navbar.js file to: './src/components/layouts/Navbarstyles.css';
I also updated the webpack module according to Naman Vyas's advice and added the CSS href to the HTML file as recommended by Pradip, but unfortunately, I'm still facing an error:
Module not found: Can't resolve './src/components/layouts/NavbarStyles.css'
Are there any other potential solutions I could explore?