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

Leading slah in url() being removed in scss files #12582

Open
bdrazen opened this issue Jul 11, 2022 · 1 comment
Open

Leading slah in url() being removed in scss files #12582

bdrazen opened this issue Jul 11, 2022 · 1 comment

Comments

@bdrazen
Copy link

bdrazen commented Jul 11, 2022

Describe the bug

I have a path set in a scss file to a resource I need referenced off the root of the domain. Since v4, the css-loader by default tries to resolve css references to src folder. I've tried using react-app-rewired to set the { url: false } option for css-loader, and it no longer complains about the missing reference, but for some reason the leading slash still gets stripped.

url('/path/to/file') -> url('path/to/file')

Did you try recovering your dependencies?

Yes, npm version: 6.14.17

Environment

current version of create-react-app: 5.0.1
running from /Users/323782896/.npm/_npx/61421/lib/node_modules/create-react-app

System:
OS: macOS 12.4
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 14.17.4 - /usr/local/bin/node
Yarn: Not Found
npm: 6.14.17 - /usr/local/bin/npm
Browsers:
Chrome: 103.0.5060.114
Edge: Not Found
Firefox: 101.0
Safari: 15.5
npmPackages:
react: ^17.0.2 => 17.0.2
react-dom: ^17.0.2 => 17.0.2
react-scripts: ^4.0.3 => 4.0.3
npmGlobalPackages:
create-react-app: Not Found

Steps to reproduce

  1. Set css-loader url option to false with react-app-rewired for use of unresolved references
// config-overrides.js

const { override, adjustStyleLoaders } = require('customize-cra');

module.exports = override(
  adjustStyleLoaders(({ use: [miniExtract, css, postcss, resolveUrl, sass] }) => {
    css.options = { ...css.options, url: false };
  })
);
  1. react-app-rewired start or react-app-rewired build

Expected behavior

url('/path/to/file')

Actual behavior

url('path/to/file')

@bdrazen
Copy link
Author

bdrazen commented Jul 11, 2022

Turns out the issue was the resolve-url-loader. Solved it by removing the root option. Did something change around this? Hadn't had this problem until upgrading to CRA 4.

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

No branches or pull requests

1 participant