Open theblondealex opened 6 days ago
The nextjs version is stripping out the #passport
part from the background url.
In sass, if the property is: background: url('./svgs/output/all-svgs-sprite.svg#passport') no-repeat;
, the output css becomes background: url('./svgs/output/all-svgs-sprite.svg') no-repeat;
.
Since the css files are processed correctly, I believe the sass-loader
config used internally by nextjs is messing up things.
The nextjs version is stripping out the
#passport
part from the background url. In sass, if the property is:background: url('./svgs/output/all-svgs-sprite.svg#passport') no-repeat;
, the output css becomesbackground: url('./svgs/output/all-svgs-sprite.svg') no-repeat;
.Since the css files are processed correctly, I believe the
sass-loader
config used internally by nextjs is messing up things.
Yes this is my thinking too
I belive the issue lies here
const lazyPostCSSInitializer = ()=>lazyPostCSS(ctx.rootDirectory, ctx.supportedBrowsers, ctx.experimental.disablePostcssPresetEnv);
const sassPreprocessors = [
// First, process files with `sass-loader`: this inlines content, and
// compiles away the proprietary syntax.
{
loader: require.resolve("next/dist/compiled/sass-loader"),
options: {
// Source maps are required so that `resolve-url-loader` can locate
// files original to their source directory.
sourceMap: true,
sassOptions: {
// The "fibers" option is not needed for Node.js 16+, but it's causing
// problems for Node.js <= 14 users as you'll have to manually install
// the `fibers` package:
// https://github.com/webpack-contrib/sass-loader#:~:text=We%20automatically%20inject%20the%20fibers%20package
// https://github.com/vercel/next.js/issues/45052
// Since it's optional and not required, we'll disable it by default
// to avoid the confusion.
fibers: false,
...sassOptions
},
additionalData: sassPrependData || sassAdditionalData
}
},
// Then, `sass-loader` will have passed-through CSS imports as-is instead
// of inlining them. Because they were inlined, the paths are no longer
// correct.
// To fix this, we use `resolve-url-loader` to rewrite the CSS
// imports to real file paths.
{
loader: require.resolve("../../../loaders/resolve-url-loader/index"),
options: {
postcss: lazyPostCSSInitializer,
// Source maps are not required here, but we may as well emit
// them.
sourceMap: true
}
}
];
const fns = [];
sass-loader here recommends putting the resolve-url-loader before the sass-loader but that causes next to fail
moved the resolve-url-loader
before the sass-loader
. got this error:
Error: resolve-url-loader: CSS error
file://scss-reproduction/nextjs/src/app/page.scss:6:6: Unknown word
You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser
You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser
Link to the code that reproduces this issue
https://github.com/theblondealex/scss-reproduction
To Reproduce
src/app/page.tsx
fileCurrent vs. Expected behavior
You will see that if the react-example is ran, the scss file is interpreted and works correctly.
Expected is that nextjs should render the url(svgs) correctly
SCSS is installed correctly as the styles are applied just not the svg loaded
Normal image works correctly in the url it is specific to .svg#ID sprite svgs
Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure, Middleware, Output (export/standalone)
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)
Additional context
No response