web-infra-dev / rsbuild

The Rspack-based build tool. It's fast, out-of-the-box and extensible.
https://rsbuild.dev/
MIT License
1.88k stars 144 forks source link

[Bug]: cannot compatible the `~` in less-loader #3535

Open priority3 opened 2 months ago

priority3 commented 2 months ago

Version

System:
    OS: macOS 12.7.2
    CPU: (8) arm64 Apple M1
    Memory: 135.14 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Browsers:
    Chrome: 128.0.6613.138
    Safari: 15.6.1
  npmPackages:
    @rsbuild/core: ^1.0.1 => 1.0.1 
    @rsbuild/plugin-less: ^1.0.1 => 1.0.1 
    @rsbuild/plugin-react: ^1.0.1 => 1.0.1

Details

Reproduce link

https://github.com/priority3/rebuild-less-loader/blob/main/src/App.less#L1

Reproduce Steps

change @import '~@animate' to @import '@animate' everything is working.

9aoy commented 2 months ago

The special processing of ~ import in less-loader causes ~@animate to be processed into @animate/, which is a special case. see: https://github.com/webpack-contrib/less-loader/blob/master/src/utils.js#L75-L77

image
priority3 commented 2 months ago

The special processing of ~ import in less-loader causes ~@animate to be processed into @animate/, which is a special case. see: webpack-contrib/less-loader@master/src/utils.js#L75-L77

image

yeah, thks so mush ! This helped me solve the problem very well; just replace the @animate to @animate/ in rsbuild.config.ts / alias everything is working; but after my testing, this issue only appeared after upgrading to version 1.0, and was completely normal in previous versions.

9aoy commented 2 months ago

This error occurs because rspack uses the native parser in the loader, see https://github.com/web-infra-dev/rspack/pull/4945.

In my test, when setting the @animate alias as below, enhance-resolve can handle this case @animate/ => node_modules/animate.less/animate.less, but rspack can't handle this. @SyMind Can you help confirm whether this error in this scenario is as expected?

    alias: {
      "@animate": "./node_modules/animate.less/animate.less",
    },

20240925-150317

chenjiahan commented 1 month ago

@SyMind cc