farm-fe / farm

Extremely fast Vite-compatible web build tool written in Rust
https://farmfe.org
MIT License
4.99k stars 167 forks source link

[Bug Report]: relative import is not working in scss #1766

Closed rushi3691 closed 1 month ago

rushi3691 commented 1 month ago

Steps to reproduce

i'm trying to migrate it from a private codebase, i don't have any other way to reproduce it full report it mentioned below

Reproduce link

No response

What is actually happening?

i'm migrating from CRA to farm

this is the code from file src/assets/scss/custom/pages/_authentication.scss

.bg-login {
    background-image: url("../../../images/Truck_wallpaper.jpg");
    padding: 60px 0px;
    background-size: cover;
    background-position: center center;
    position: relative;
    border-radius: 0px 0px 50% 50%;
}

this, importing image, is working is CRA,

but when i migrate from CRA to farm, it says path not found for the image

but when i change the path, as

.bg-login {
    background-image: url("/images/Truck_wallpaper.jpg");
    padding: 60px 0px;
    background-size: cover;
    background-position: center center;
    position: relative;
    border-radius: 0px 0px 50% 50%;
}

,its working

i don't want to change the code to keep it compatible with old ways

here's the directory structures

.
├── farm.config.js
├── package.json
├── public
│   ├── index.html
├── src
│   ├── App.css
│   ├── assets
│   ├── index.css
│   └── index.jsx
└── webpack.config.js

and for assets folder

src/assets
├── css
│   ├── Custom.css
│   ├── ReactToastify.css
│   └── tableComponent.css
├── fonts
│   └── summernote.woff
├── images
│   └──  Truck_wallpaper.jpg
└── scss
    ├── app-dark.scss
    ├── app.scss
    ├── bootstrap-dark.scss
    ├── bootstrap.scss
    ├── custom
    │   ├── components
    │   ├── fonts
    │   │   └── _fonts.scss
    │   └── pages
    │       └──  _authentication.scss
    ├── tasks.scss
    └──  theme.scss

error:

[ Farm ] Error: Failed to start the server
Caused by: Error: Can not resolve `../../../images/Truck_wallpaper.jpg` from src/components/CommonForBoth/rightbar.scss.
Original error: None.

Potential Causes:
1.The file that `../../../images/Truck_wallpaper.jpg` points to does not exist.
2.Install it first if `../../../images/Truck_wallpaper.jpg` is an dependency from node_modules, if you are using pnpm refer to [https://pnpm.io/faq#pnpm-does-not-work-with-your-project-here] for solutions.
3. If `../../../images/Truck_wallpaper.jpg` is a alias, make sure your alias config is correct.

farm.config.js

import { defineConfig } from '@farmfe/core';
import sassPlugin from '@farmfe/plugin-sass';

export default defineConfig({
  compilation: {
    input: {
      index: './public/index.html',
      app: './src/index.jsx'
    },
  },
  plugins: [
    '@farmfe/plugin-react',
    sassPlugin()
  ]
});

System Info

System:
    OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
    Memory: 7.55 GB / 15.32 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 16.20.2 - ~/.nvm/versions/node/v16.20.2/bin/node
    npm: 8.19.4 - ~/.nvm/versions/node/v16.20.2/bin/npm
    bun: 1.1.26 - ~/.bun/bin/bun
  Browsers:
    Chrome: 128.0.6613.137
  npmPackages:
    @farmfe/core: ^1.3.19 => 1.3.19
fu050409 commented 1 month ago

Hi there, thanks to your report but sorry that I cannot reproduce this issue. The relative import of images in .scss files works fine on my local machine.

Besides, I found your error message is caused by file src/components/CommonForBoth/rightbar.scss but not src/assets/scss/custom/pages/_authentication.scss, are you sure the relative directory is proper?