Skip to content
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

[Bug]: Error when using absolute path to reference online resources (non-local resources) in css/less #1948

Closed
tiannengyu opened this issue Mar 27, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@tiannengyu
Copy link

Version

rsbuild@0.4.6

Details

@font-face { font-family: DingTalk; src: url('/amcp/image/font/DingTalkJinBuTi.ttf'); }
报错信息
`
error Compile error:
Failed to compile, check the errors for troubleshooting.
File: ./src/routes/InvestmentCalendar/components/index.less
× Resolve error: Can't resolve '/amcp/image/font/DingTalkJinBuTi.ttf' in '/Users/tiannengyu/private/gitlab2/zgzx-trade-manager-front/src/routes/InvestmentCalendar/components'
╭─[1:1]
1 │ @font-face{
2 │ font-family: DingTalk;
3 │ src: url(/amcp/image/font/DingTalkJinBuTi.ttf);
· ─────────────────────────────────────────
4 │ }
5 │ .src-routes-InvestmentCalendar-components-index__calendar_common-_9cab1__zgtz {
╰────

start Compiling...
`
构建时报错,在css和less中使用如上方式,src :url('线上资源绝对路径')会报错

Reproduce link

/

Reproduce Steps

/

@tiannengyu tiannengyu added the bug Something isn't working label Mar 27, 2024
@xc2
Copy link
Collaborator

xc2 commented Mar 27, 2024

please try out / 请尝试:

export default defineConfig({
  // ...
  source: {
    // ...
    alias: {
      "/amcp/image/font": false,
    },
  },
  // ...
});

@tiannengyu
Copy link
Author

please try out / 请尝试:

export default defineConfig({
  // ...
  source: {
    // ...
    alias: {
      "/amcp/image/font": false,
    },
  },
  // ...
});

尝试这么做,在mac下构建正常,但在部分windows系统机器下,会报如下错误
clipbord_1711705567526

@ChenXplorer
Copy link

the same as u

@tiannengyu
Copy link
Author

@xc2 可以协助看下这个问题吗

@chenjiahan
Copy link
Member

用 externals 也可以避免 resolve 这个模块,比如:

export default defineConfig({
  output: {
    externals: [/\/image\/font/g],
  },
});

@ChenXplorer
Copy link

但有个疑问,为何mac 没问题,win有问题。

@chenjiahan
Copy link
Member

通常是路径分隔符的问题,Mac 和 Windows 采用了不同的路径分隔符

@ChenXplorer
Copy link

请问下,rsbuild 可以解决这个问题吗,不需要额外的配置(例如无额外配置,mac可以正常build)

@chenjiahan
Copy link
Member

目前来说不会解决,这个路径会触发 webpack / Rspack 的 resolve 逻辑,在 create-react-app 中也能复现该问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants