更新软件包后,无法编译.scss文件。编译器显示以下错误:
./ src / app / components / settings / settings.component.scss中的错误 模块构建失败(来自./node_modules/sass-loader/lib/loader.js):
$font-family: 'Segoe UI';
^
Expected "{".
src\styles\_variables.scss 1:26 root stylesheet
stdin 1:9 root stylesheet
in E:\Work\SoftServe\JiraCloud\src\MicrosoftTeamsIntegration.Jira\ClientApp\src\styles\_variables.scss (line 1, column 26)
我的package.json:
{
"name": "proj",
"version": "255.255.255",
"license": "MIT",
"scripts": {
"ng": "./node_modules/.bin/ng",
"start": "ng serve",
"build": "ng build",
"test": "node --no-deprecation ./node_modules/@angular/cli/bin/ng test --watch=false --progress=false",
"lint": "tslint --fix -c ./tslint.json 'src/**/*.ts'"
},
"private": true,
"dependencies": {
"@angular/animations": "6.1.7",
"@angular/cdk": "6.4.7",
"@angular/cli": "6.2.2",
"@angular/common": "6.1.7",
"@angular/compiler": "6.1.7",
"@angular/compiler-cli": "6.1.7",
"@angular/core": "6.1.7",
"@angular/forms": "6.1.7",
"@angular/http": "6.1.7",
"@angular/material": "6.4.7",
"@angular/platform-browser": "6.1.7",
"@angular/platform-browser-dynamic": "6.1.7",
"@angular/router": "6.1.7",
"@types/applicationinsights-js": "1.0.7",
"angular2-spinner": "1.0.10",
"applicationinsights-js": "1.0.20",
"ng-click-outside": "4.0.0",
"rxjs": "6.3.2",
"zone.js": "0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "0.8.2",
"@types/jasmine": "2.8.8",
"@types/jasminewd2": "2.0.3",
"codelyzer": "4.4.4",
"jasmine-core": "3.2.1",
"jasmine-spec-reporter": "4.2.1",
"karma": "3.0.0",
"karma-chrome-launcher": "2.2.0",
"karma-coverage-istanbul-reporter": "2.0.4",
"karma-jasmine": "1.1.2",
"karma-jasmine-html-reporter": "1.3.1",
"karma-trx-reporter": "0.2.9",
"prettier": "1.14.2",
"protractor": "5.4.1",
"puppeteer": "1.8.0",
"ts-node": "7.0.1",
"tslint": "5.11.0",
"tslint-config-prettier": "1.15.0",
"tslint-plugin-prettier": "1.3.0",
"typescript": "2.9.2"
}
}
我的_variables.scss文件:
$font-family: 'Segoe UI';
$black: #000000;
$white: #FFFFFF;
我的styles.scss。它表明它不能导入“变量”。但是,应该通过部分文件的scss约定。我的_icons.scss文件也可以使用。其中仅包含$ok: '\e412';
@import "~@angular/material/prebuilt-themes/deeppurple-amber.css";
@import "common/inputs.component.scss";
@import "common/buttons.component.scss";
@import "common/checkboxes.component.scss";
@import "common/radio-buttons.component.scss";
@import "common/fields.scss";
@import "./cookie-consent.scss";
@import "./generic.scss";
@import "./angular-material.overrides.scss";
@import "./editable-field.scss";
@import "./variables";
html {
max-height: 98%;
}
body {
font-family: $font-family;
font-weight: 400;
font-size: 14px;
background-color: white;
overflow-y: hidden;
}
我的angular.json文件
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"jiratab": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": [
"src/assets",
"src/tabConfig.html",
"src/loginResult.html",
"src/logout.html",
"src/login.html",
"src/fonts.css",
"src/favicon.ico"
],
"styles": [
"src/styles/styles.scss"
],
"scripts": [],
"stylePreprocessorOptions": {
"includePaths": [
"src/styles"
]
}
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "jiratab:build"
},
"configurations": {
"production": {
"browserTarget": "jiratab:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "jiratab:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"src/styles.css"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"jiratab-e2e": {
"root": "",
"sourceRoot": "",
"projectType": "application"
}
},
"defaultProject": "jiratab",
"schematics": {
"@schematics/angular:component": {
"prefix": "app",
"styleext": "scss"
},
"@schematics/angular:directive": {
"prefix": "app",
"styleext": "scss"
}
}
}
我也尝试过这样导入
import "./_variables.scss";
import "variables";
import "./variables.scss"
但是这些都不行
答案 0 :(得分:0)
由于全局npm软件包而导致错误 我已完成以下操作:
从%appdata%删除npm文件夹内容 安装@ angular / cli 并在我的项目中使我成为npm
因此一切都很好 仍然不知道问题出在哪里,但这对我有所帮助