New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't resolve assets file path in SCSS file #10990
Comments
I've resolved this issue by referring to the content below. |
@stegano I added
|
Hi @phong10119, The settings I've tried are below. ...
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
auto: true,
localIdentName: "[local]--[hash:base64:5]",
},
},
},
'resolve-url-loader',
'sass-loader'
]
},
... |
Thank you @stegano, I had to make the import in global.module.scss relative. It works now! |
Hi, @stegano I'm facing the error exactly the same as you. My config in main.js as below
The error output is
|
Hi, @lethanhtupk |
Seems like you missing this? It's in resolve-url-loader doc |
@lethanhtupk |
@phong10119 @stegano thanks for the response directory
I found that if I changed the path in scss file into |
@lethanhtupk |
@stegano |
@lethanhtupk Unfortunately, the simplest way I know of is to set an alias for the webpack. 😥 |
You can use
import '!style-loader!css-loader!resolve-url-loader!sass-loader!../src/styles/my-global-file.scss' or
const path = require('path');
module.exports = {
webpackFinal: async (config, { configType }) => {
config.module.rules.push({
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'resolve-url-loader', 'sass-loader'],
include: path.resolve(__dirname, '../'),
});
return config;
},
}; |
Hello @ajeetshah ... which versions of "style-loader, css-loader, resolve-url-loader, sass-loader" worked for you? |
I had solved this (assets file path) issue by using method-1 i.e. After a few months, I upgraded storybook to V6 and found that I no longer needed to use method-1 and I could just write To answer your question, I had PS: I used storybook in a React project built with CRA. |
Found next solution (for css, not scss):
|
Thanks @PFight , your suggestion helped resolve my path issue (solution below). I'm using NextJS + SCSS + NextJS public folder for font files + Storybook. The issue was css-loader was trying to resolve the URL when I needed it left as is. // .storybook/main.js
module.exports = {
addons: [
"@storybook/preset-scss",
],
staticDirs: ["../public"],
webpackFinal: async (config) => {
for (let rule of config.module.rules) {
if (rule.use && rule.use.length > 0) {
for (let use of rule.use) {
if (use.loader && use.loader.includes("/css-loader/")) {
use.options = {
...use.options,
url: (url, resourcePath) => !url.startsWith("/"),
};
}
}
}
}
return config;
},
}; My erroring SCSS file:
Error:
|
Hey Stengato, is there a way of using absolute import for asset file in scss? // absolute imports // relative imports Your input would be highly appreciated |
Hi @algomachine007 |
@algomachine007 Can you show me the next.config.js file you are using? |
// next.config.js module.exports = { Hey, finally figured it out, wouldn't have been possible without your help, thanks man |
Describe the bug
When importing a file using
@import
, it seems that there is a problem with the image path of the imported file. The relative path of the file in SCSS should be based on the imported target file, but it doesn't seems to be. (Please see code snippet)Expected behavior
mixins
folder pathCode snippets
Output:
ERROR in ./src/index.scss (./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/index.scss)
Module not found: Error: Can't resolve './images/test.svg' in '/Users/test/src/index'
System:
The text was updated successfully, but these errors were encountered: