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 using url(...) in css file #641

Closed
alefduarte opened this issue Jan 3, 2025 · 1 comment
Closed

[Bug]: Error using url(...) in css file #641

alefduarte opened this issue Jan 3, 2025 · 1 comment

Comments

@alefduarte
Copy link

Version

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
    Memory: 2.82 GB / 31.67 GB
  Browsers:
    Edge: Chromium (127.0.2651.86)
    Internet Explorer: 11.0.19041.4355

Details

I have a CSS file with my local font

@font-face {
  font-family: 'Gilroy';
  font-style: normal;
  font-weight: 300;
  src: url('../assets/fonts/Gilroy-Light.otf');
}

When I build it, I get the error

File: C:\xxx\packages\ui\dist\context\context.css:1:1
  × Module not found: Can't resolve '/static/font/Gilroy-Light.otf' in 'C:\xxx\packages\ui\dist\context'
   ╭─[5:36]
 3 │ import ___CSS_LOADER_API_IMPORT___ from "../../../../node_modules/@rsbuild/core/compiled/css-loader/api.js";
 4 │ import ___CSS_LOADER_GET_URL_IMPORT___ from "../../../../node_modules/@rsbuild/core/compiled/css-loader/getUrl.js";
 5 │ var ___CSS_LOADER_URL_IMPORT_0___ = new URL("/static/font/Gilroy-Light.otf", import.meta.url);
   ╰────

If I check the built CSS in the dist folder, it changes the file to

@font-face {
  font-family: Gilroy;
  font-style: normal;
  font-weight: 300;
  src: url(/static/font/Gilroy-Light.otf);
}

If I manually change the src to

  src: URL(../static/font/Gilroy-Light.otf);

then it works.
I also tried to use

tools: {
    cssLoader: {
      url: false,
    },
  },

but then the fonts are not exported.

I tried an example using codesandbox and in this example, only by using URL(...) I got an error:

error   Compile error: 
Failed to compile, check the errors for troubleshooting.
File: /project/workspace/packages/ui/src/styles/fonts.css?__rslib_entry__:1:1
  × Module build failed:
  ╰─▶   × TypeError: Cannot read properties of undefined (reading '__esModule')
        │     at handleExports (file:///project/workspace/node_modules/.pnpm/@[email protected][email protected]/node_modules/@rslib/core/dist/libCssExtractLoader.js:34:45)
        │     at file:///project/workspace/node_modules/.pnpm/@[email protected][email protected]/node_modules/@rslib/core/dist/libCssExtractLoader.js:121:9
        │     at /project/workspace/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@rspack/core/dist/index.js:6301:13

if I try url: false it builds fine but the font file is not exported.

Reproduce link

https://codesandbox.io/p/devbox/sx9t7q

Reproduce Steps

  1. run pnpm i to install all dependencies
  2. run pnpm build --filter=@acme/ui to build only the ui package.

You'll see the error already

@Timeless0911
Copy link
Contributor

It has been fixed by #573 and released in v0.1.5. You can update @rslib/core to latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants