Reputation: 159
I'm just starting out with Angular 6, using the Angular CLI and getting familiar with the file structure. I intend on using SCSS to create a singular global stylesheet. However, when i compile i am receiving the error:
ERROR in ./src/app/top-bar/top-bar.component.scss
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
// Copyright Joyent, Inc. and other Node contributors.
^
Invalid CSS after "...N THE SOFTWARE.": expected 1 selector or at-
rule, was "var formatRegExp = "
in /Users/me/Documents/projects/node_modules/util/util.js
(line 1, column 1)
My custom scss folder is located under src/assets/scss
.
My top-bar component is located under src/app/top-bar
.
I am trying to access src/assets/scss/app.scss
in src/app/top-bar/top-bar.component.scss
and receiving the above error.
I've tried numerous ways of importing the file @import "~/assets/scss/app.scss";
and @import "../assets/scss/app.scss";
to include the necessary variables but i cant be sure of what i'm doing wrong as the error seems vague and not pointed at any specific file besides a core angular utility.
If anyone can shed some light, even on the debugging process for such an error it would help immensely.
Upvotes: 1
Views: 1406
Reputation: 1
Workaround for Angular7+ (unable to revert sass-loader version) & Foundation6+ & SASS combination:
Do not @import util/util
from foundation in your .scss files but separated packages combination (breakpoint, color, direction, flex, math, mixins, selector, typography, unit, value), based on what you need or trick it with ./util/util
. Also foundation.scss
and settings.scss
imports util inside them and so this files should be avoided or patched locally until sass-loader fix.
Upvotes: 0
Reputation: 2242
As pointed out by @crimbo the problem is in https://github.com/webpack-contrib/sass-loader/issues/556 , but I cannot rename files, because I use third party library ( Foundation 6 ).
I have downgraded to [email protected]
npm install --save-dev [email protected]
and it works for me for Angular 7.1.4 which used originally [email protected]
As per release notes https://github.com/webpack-contrib/sass-loader/releases/tag/v7.0.0 the breaking changes are:
which are not problem for my case
Upvotes: 1
Reputation: 11251
I encountered the same problem. The root cause is a bug in the SCSS file loader/resolver used by webpack (used by the @angular/cli) that loads JS files in addition to SCSS files.
The bug is that JS files take precedence over SCSS files. The GitHub issue is here:
https://github.com/webpack-contrib/sass-loader/issues/556
The bad news is that the issue has been open for 8 months, and pull requests to fix it haven't been accepted.
The good news is that you can work around the problem by using SCSS file names that don't match JS filenames in node_modules
subdirectories.
For example, I had a SCSS file named _util.scss
, and so my error was:
Invalid CSS after "...N THE SOFTWARE.": expected 1 selector or at-rule, was "var formatRegExp = "
in C:\src\project\node_modules\util\util.js (line 1, column 1)
My fix was to rename my SCSS file to _sass-util.scss
. Hope that helps.
Upvotes: 1