You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Next.js v12, webpack has troubles when importing a CSS file that has a comment in SVG URI. Note that this previously worked fine in Next.js v11.
This is the error message.
Module build failed: UnhandledSchemeError: Reading from "data:image/svg+xml;charset=UTF-8,<?xml version="1.0" encoding="utf-8"?>
<!./-- Generator: Adobe Illustrator 24.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="dx_l_3" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="24px" height="24px" viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;" xml:space="preserve">
<path style="fill:" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "data:" URIs.
at /home/addison/Node.js/nextjs-temp/fix-css-svg-bug/node_modules/next/dist/compiled/webpack/bundle5.js:49033:25
at Hook.eval [as callAsync] (eval at create (/home/addison/Node.js/nextjs-temp/fix-css-svg-bug/node_modules/next/dist/compiled/webpack/bundle5.js:135839:10), <anonymous>:16:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/home/addison/Node.js/nextjs-temp/fix-css-svg-bug/node_modules/next/dist/compiled/webpack/bundle5.js:135641:14)
at Object.processResource (/home/addison/Node.js/nextjs-temp/fix-css-svg-bug/node_modules/next/dist/compiled/webpack/bundle5.js:49030:8)
at processResource (/home/addison/Node.js/nextjs-temp/fix-css-svg-bug/node_modules/next/dist/compiled/webpack/bundle5.js:134812:11)
at iteratePitchingLoaders (/home/addison/Node.js/nextjs-temp/fix-css-svg-bug/node_modules/next/dist/compiled/webpack/bundle5.js:134763:10)
at runLoaders (/home/addison/Node.js/nextjs-temp/fix-css-svg-bug/node_modules/next/dist/compiled/webpack/bundle5.js:134989:2)
at NormalModule._doBuild (/home/addison/Node.js/nextjs-temp/fix-css-svg-bug/node_modules/next/dist/compiled/webpack/bundle5.js:49020:3)
at NormalModule.build (/home/addison/Node.js/nextjs-temp/fix-css-svg-bug/node_modules/next/dist/compiled/webpack/bundle5.js:49164:15)
at /home/addison/Node.js/nextjs-temp/fix-css-svg-bug/node_modules/next/dist/compiled/webpack/bundle5.js:23636:12
Below is an snippet of CSS that causes the bug. If you add this to a CSS file, Next.js will crash when attempting to build (i.e. npm run build).
This bug is identical to the one posted here: #30721. The issue was closed as being fixed but that's incorrect. The issue is still present in the latest Next.js (even canary, I've tried).
What's the bug
I've figured out what's causing the problem, I just don't know how it's supposed to work, so maybe someone can enlighten me.
The problem is that the CSS snippet above has a ! inside it (even though it's URL encoded). In the SVG, it has a comment which is denoted by <!--, which is what's causing the issue.
The prefix is meant to be used in Webpack to specify a specific module when importing, so I presume that's why the logic is present. I know this is the problem because when I remove it locally, the build error goes away.
This code was added March 24th, 2021 in webpack-contrib/css-loader (source: webpack-contrib/css-loader@263427e). No message was given as to why it was added. This code was then copied locally to Next.js last summer I believe.
To Reproduce
Add the CSS snippet provided above to your Next.js project and it will have this issue. Just make sure the CSS file is imported in the source code somewhere.
The text was updated successfully, but these errors were encountered:
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Run
next info
(available from version 12.0.8 and up)What version of Next.js are you using?
12.0.8
What version of Node.js are you using?
16.13.2
What browser are you using?
N/A
What operating system are you using?
Ubuntu (WSL)
How are you deploying your application?
npm run build
Describe the Bug
In Next.js v12, webpack has troubles when importing a CSS file that has a comment in SVG URI. Note that this previously worked fine in Next.js v11.
This is the error message.
Below is an snippet of CSS that causes the bug. If you add this to a CSS file, Next.js will crash when attempting to build (i.e.
npm run build
).This is the URL-decoded SVG file:
This bug is identical to the one posted here: #30721. The issue was closed as being fixed but that's incorrect. The issue is still present in the latest Next.js (even canary, I've tried).
What's the bug
I've figured out what's causing the problem, I just don't know how it's supposed to work, so maybe someone can enlighten me.
The problem is that the CSS snippet above has a
!
inside it (even though it's URL encoded). In the SVG, it has a comment which is denoted by<!--
, which is what's causing the issue.The bug occurs in
postcss-url-parser
which is responsible for parsing theurl()
function in CSS files. See here: https://github.com/webpack-contrib/css-loader/blob/c5062db3fc849d882a07b9f2c9f66f00325c8896/src/plugins/postcss-url-parser.js#L253-L258The prefix is meant to be used in Webpack to specify a specific module when importing, so I presume that's why the logic is present. I know this is the problem because when I remove it locally, the build error goes away.
This code was added March 24th, 2021 in webpack-contrib/css-loader (source: webpack-contrib/css-loader@263427e). No message was given as to why it was added. This code was then copied locally to Next.js last summer I believe.
To Reproduce
Add the CSS snippet provided above to your Next.js project and it will have this issue. Just make sure the CSS file is imported in the source code somewhere.
The text was updated successfully, but these errors were encountered: