angular-cli: Ng build fails. CssSyntaxError since 1.7.0-rc.0
Versions
Error occurs since v1.7.0-rc.0
Angular CLI: 1.7.0-rc.0
Node: 8.9.4
OS: win32 x64
Angular: 5.2.5
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.7.0-rc.0
@angular-devkit/build-optimizer: 0.3.1
@angular-devkit/core: 0.3.1
@angular-devkit/schematics: 0.3.1
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.0-rc.0
@schematics/angular: 0.3.1
@schematics/package-update: 0.3.1
typescript: 2.6.2
webpack: 3.10.0
Observed behavior
ERROR in ./node_modules/raw-loader!./node_modules/postcss-loader/lib??embedded!./src/assets/styles/page.css
(Emitted value instead of an instance of Error) CssSyntaxError: C:\Users\{omitted}\angular-project\src\assets\styles\page.css:259:2159: Can't resolve '%23linearGradient-1' in 'C:\Users\{omitted}\angular-project\src\assets\styles'
> 259 | background: transparent url("../img/icon.svg") no-repeat 50% 0; ^
260 | }
I get similar error messages for each svg file. The page.css is listed in angular-cli.json styles array.
Repro steps
ng build
Possible breaking commits: https://github.com/angular/angular-cli/commit/4a745c9 https://github.com/angular/angular-cli/commit/fa175d8
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 27
- Comments: 55 (5 by maintainers)
This is happening with SVG only.
1.7.1
is solving the issue for me, thanks a lot @clydin1.7.1 did not fix the issue for me. I had to roll back to 1.6.0. I’m seeing the error on unquoted urls for fonts.
Warning: the path it´s not relative to the partial .scss file
For many people the error will be caused when trying to load a resource relative to the file. What Webpack is doing is trying to resolve the paths relative to the entry file.
You can put the SVGs or webfonts inside the assets folder and update the path accordingly.
Same issue as @embryologist Referring to files via css url() without “” causes the build to crash. This should work, as it has a different meaning when using for example sass.
Can confirm that it’s not working in 1.7.1
Same here with v1.7.0.
I can confirm this bug. I have exactly the same issue.
For me it appeared as soon as I updated to version 1.7, the issue was not in 1.6.
Happen with
src: local('Material Icons'), local('MaterialIcons-Regular'), url(../../assets/fonts/material-icon.woff2) format('woff2');
too with v 1.7.1Ok. Just wrap url content inside “”, fix the problem
I am getting the same error with single svg background url.
Guys, Did you try to specify path in this way? For me it’s working fine.
For everyone still having issues with unquoted url functions, a fix has been merged in master (#9738) and will be available in 1.7.2 which will be released this week.
@wonkim00 thank you, I also had success with cli 1.6.8
@nidhididi Yes. After deleting the node_modules folder, editing to “@angular/cli”: “~1.6.0” in package.json, and running npm install again (which pulled cli 1.6.8), ng build ran successfully.
Same, 1.7.0 caused failing builds, pinned version to 1.6.0, builds are passing again.
I’m on @angular/cli 1.7.4 and I’ve had the same issue while I was trying to load fonts.
I fixed the problem by assigning url value to scss variable, hope it helps!
The folder “fonts”, is it included in angular-cli.json file as a static folder?
You can navigate to localhost:4000/webpack-dev-server to see if your targeting folder was correctly emitted and if your given don’t url points to that folder.
I’m having the same issue and it’s something to do with the
postcss-cli-resources
plugin. Apparently, it doesn’t quite supportbackground
properties with multiple backgrounds, if the last one is not a URL.Example:
Will get compiled to:
@clydin this is the commit that caused my regression (and possibly the others in this thread): https://github.com/angular/angular-cli/commit/eb102275bdd1a05369ff2d1c588ee4040ef0c45d
@wonkim00 did that work for you?
1.7 is broken. Reverting to 1.6.