Angular 5:ng build - -prod 由于 clean-css 失败:无法读取未定义的属性“行" [英] Angular 5: ng build - -prod fails due to clean-css: Cannot read property 'line' of undefined
问题描述
我的应用在 Angular 5.2.6 下.
ng serve
一切正常,但是当运行 ng build --prod
时,它需要一段时间才能失败.错误似乎与 clean-css 操作有关.
Things are normal with ng serve
, but when running ng build --prod
, it takes a while, before failing. The errors seem to have to do with the clean-css actions.
错误跟踪:
92% chunk asset optimization/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/input-source-map-tracker.js:37
if (originalPosition.line === null && line > 1 && selectorFallbacks > 0) {
^
TypeError: Cannot read property 'line' of undefined
at originalPositionFor (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/input-source-map-tracker.js:37:23)
at originalMetadata (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/tokenizer/tokenize.js:486:43)
at intoTokens (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/tokenizer/tokenize.js:240:75)
at tokenize (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/tokenizer/tokenize.js:74:10)
at fromStyles (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/read-sources.js:147:12)
at fromString (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/read-sources.js:48:10)
at doReadSources (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/read-sources.js:33:12)
at readSources (/home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/reader/read-sources.js:24:10)
at /home/khalidvm/Desktop/Workspace/Front/frontend_v2/node_modules/clean-css/lib/clean.js:99:12
at _combinedTickCallback (internal/process/next_tick.js:95:7)
at process._tickCallback (internal/process/next_tick.js:161:9)
好像是清理css的时候失败了.
It seems that it fails when cleaning css.
这是我的 package.json:
{
"name": "test",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"karma": "ng test",
"test": "jest",
"test:watch": "jest --watch",
"test:ci": "jest --runInBand",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.2.6",
"@angular/common": "^5.2.6",
"@angular/compiler": "^5.2.6",
"@angular/core": "^5.2.6",
"@angular/forms": "^5.2.6",
"@angular/http": "^5.2.6",
"@angular/platform-browser": "^5.2.6",
"@angular/platform-browser-dynamic": "^5.2.6",
"@angular/platform-server": "^5.2.6",
"@angular/router": "^5.2.6",
"angular-2-local-storage": "^1.0.1",
"angular2-drag-scroll": "1.2.6",
"angular2-jwt": "^0.2.3",
"angular2-multiselect-dropdown": "1.3.6",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"file-saver": "^1.3.3",
"font-awesome": "^4.7.0",
"hammerjs": "^2.0.8",
"jest-preset-angular": "^2.0.5",
"json2typescript": "1.0.5",
"lodash": "^4.12.0",
"moment": "^2.18.1",
"ng-http-interceptor": "^3.1.2",
"ng2-smart-table": "^1.1.0",
"ngx-bootstrap": "2.0.2",
"ngx-filesaver": "0.0.2",
"ngx-modialog": "^5.0.0",
"ngx-pagination": "^3.0.1",
"ngx-tooltip": "0.0.9",
"npm": "^5.2.0",
"proxy-polyfill": "^0.1.7",
"rxjs": "^5.5.6",
"sha1": "^1.1.1",
"smoothscroll-polyfill": "^0.3.5",
"web-animations-js": "^2.2.5",
"zone.js": "^0.8.8"
},
"devDependencies": {
"@angular/cli": "1.7.1",
"@angular/compiler-cli": "^5.2.6",
"@types/jasmine": "2.5.38",
"@types/jest": "^20.0.5",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"jest": "^20.0.4",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^0.2.0",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.0",
"ts-jest": "^20.0.7",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "2.4.2"
},
"jest": {
"preset": "jest-preset-angular",
"setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts",
"transformIgnorePatterns": [
"node_modules/(?!json2typescript|angular2-multiselect-dropdown|ngx-filesaver|ngx-bootstrap|angular2-drag-scroll)"
]
}
}
我已经清理了 npm 缓存,删除了 package-lock.json,重新安装了 node_modules,我还降级到了 angular-cli 1.6.8 和 1.6.8 但是,对于 1.6.x 出现了另一个问题,因此我被告知升级到 1.7.x.
I've cleaned npm cache, deleted the package-lock.json, re-installed node_modules, I have also downgraded to angular-cli 1.6.8 and 1.6.8 but, with 1.6.x there is another issue which appears, therefore I was told to upgrade to 1.7.x.
但不幸的是,情况变得更糟.
But unfortenately this comes worse.
另外手动美化我所有的css数据也很困难,因为我有一个巨大的css数据.
Also it's difficult to beautify manually all my css data, because I have a huge css data.
建议?
推荐答案
运行 sass/css 文件以显示所有空格字符.我很确定在您的属性之间有一个不间断空间,这会导致它损坏.类似的东西
Run your sass/css files to show all space characters. I am pretty sure there is a non-breaking space somewhere between your properties which is causing it to break. something like
{
color:[non-breaking-space]#123456;
}
您可以通过安装一个名为 Highlight Bad Chars 的 VS 代码插件来发现这些坏字符https://marketplace.visualstudio.com/items?itemName=wengerk.突出显示坏字符
You can spot these bad characters by installing a VS code plugin called Highlight Bad Chars https://marketplace.visualstudio.com/items?itemName=wengerk.highlight-bad-chars
这篇关于Angular 5:ng build - -prod 由于 clean-css 失败:无法读取未定义的属性“行"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!