SCSS Error: can not read files in public path

I have an assets folder that contain some other files with images and svgs in it in the public file of my project so... => navbar.scss ...I declared a variable with path below
$logo-path: "/assets/logos/black.svg”;
$logo-path: "/assets/logos/black.svg”;
Error: Module not found: Error: Can't resolve '../../../logos/mobile.jpg’
Failed to compile.

Module not found: Error: Can't resolve '../../../logos/mobile.jpg' in '/src/assets/css/sass/themes'
ERROR in ./src/assets/css/sass/themes/navbar.scss (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[7].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[7].use[2]!./node_modules/resolve-url-loader/index.js??ruleSet[1].rules[0].oneOf[7].use[3]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[7].use[4]!./src/assets/css/sass/themes/navbar.scss) 5:36-100
Module not found: Error: Can't resolve '../../../logos/mobile.jpg' in '/src/assets/css/sass/themes’
Failed to compile.

Module not found: Error: Can't resolve '../../../logos/mobile.jpg' in '/src/assets/css/sass/themes'
ERROR in ./src/assets/css/sass/themes/navbar.scss (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[7].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[7].use[2]!./node_modules/resolve-url-loader/index.js??ruleSet[1].rules[0].oneOf[7].use[3]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[7].use[4]!./src/assets/css/sass/themes/navbar.scss) 5:36-100
Module not found: Error: Can't resolve '../../../logos/mobile.jpg' in '/src/assets/css/sass/themes’
10 Replies
vince
vince16mo ago
Can we see your folder structure?
Leke
Leke16mo ago
vince
vince16mo ago
Are you using absolute paths? It seems you configured your absolute path to start at src/ You'd need to configure it to start in your react root directory And then do something like public/assets/logos/{image}
Leke
Leke16mo ago
ok The problem is that i didnt write the code , its an existing project im trying to work on
vince
vince16mo ago
I would talk to your team about it then because if you change where the absolute path is pointed to it will change all other import paths
Leke
Leke16mo ago
please how do i change path ? Im just gonna try it if it solves the problem'
vince
vince16mo ago
I'm not sure off the top of my head, you'd have to look up how to set absolute paths in react
vince
vince16mo ago
Stack Overflow
Import react components with absolute path
Here is my test file // /imports/components/main.test.js import React from 'react' import { shallow, mount } from 'enzyme' import Main from './main' import TextInput from "/imports/ui/textInput" ....
vince
vince16mo ago
You will need to change every other path that uses an absolute path though. Easier option would be to just move the asset folder into src But I'm not sure if your team wants that
Leke
Leke16mo ago
ok thanks