farm-fe / farm

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

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

Open rushi3691 opened 5 days ago

rushi3691 commented 5 days ago

Steps to reproduce

clone https://github.com/rushi3691/farm-sass-issue

  1. install dependencies - npm i
  2. run - npm start (which works fine)
  3. run - npm run start:farm (doesn't work)

Reproduce link

No response

What is actually happening?

the project contains some .scss files with some image imports, farm is not able to detect those imports and throwing error

[ Farm ] Error: Failed to start the server Caused by: Error: Can not resolve ../../../images/Truck_wallpaper.jpg from src/assets/scss/theme.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.

  1. If ../../../images/Truck_wallpaper.jpg is a alias, make sure your alias config is correct.

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: 5.05 GB / 15.32 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
    npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
    pnpm: 9.7.0 - ~/.bun/bin/pnpm
    bun: 1.1.26 - ~/.bun/bin/bun
  Browsers:
    Chrome: 128.0.6613.137
  npmPackages:
    @farmfe/core: ^1.3.21 => 1.3.21
shulandmimi commented 3 days ago

It is recommended to use aliases to load resources in public scss files

// farm.config.js
import path from 'node:path';

export default defineConfig({
    compilation: {
        // ..
        resolve: {
            '@': path.resolve(process.cwd(), './src/assets'),
        }
    }
})

// _authentication.module.scss

background-image: url("@/images/Truck_wallpaper.jpg");