I upgraded my existing app from Angular 5 to 6.
After i run ng serve
i get the following error:
The node_modules/font-awesome/fonts asset path must start with the project source root. Error: The node_modules/font-awesome/fonts asset path must start with the project source root. at assetPatterns.map.assetPattern (/home/kay/Documents/<>/<>/node_modules/@angular-devkit/build-angular/src/utils/normalize-asset-patterns.js:37:23)
As you can see below i have an assets array that pulls in fonts from the node module package. This was not an issue in Angular 5.
angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"demo": {
"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/favicon.ico",
"../node_modules/font-awesome/fonts"
],
"styles": [
"src/styles.scss",
"src/theme.scss",
"node_modules/font-awesome/css/font-awesome.min.css"
],
"scripts": [
"node_modules/hammerjs/hammer.min.js",
"node_modules/auth0-js/build/auth0.min.js",
"node_modules/moment/min/moment.min.js",
"node_modules/ua-parser-js/dist/ua-parser.min.js",
"node_modules/d3/dist/d3.min.js",
"node_modules/wordcloud/src/wordcloud2.js",
"node_modules/chart.js/dist/Chart.bundle.min.js",
"node_modules/progressbar.js/dist/progressbar.min.js"
]
},
"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": "demo:build"
},
"configurations": {
"production": {
"browserTarget": "demo:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "demo:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"karmaConfig": "./karma.conf.js",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"scripts": [
"node_modules/hammerjs/hammer.min.js",
"node_modules/auth0-js/build/auth0.min.js",
"node_modules/moment/min/moment.min.js",
"node_modules/ua-parser-js/dist/ua-parser.min.js",
"node_modules/d3/dist/d3.min.js",
"node_modules/wordcloud/src/wordcloud2.js",
"node_modules/chart.js/dist/Chart.bundle.min.js",
"node_modules/progressbar.js/dist/progressbar.min.js"
],
"styles": [
"src/styles.scss",
"src/theme.scss",
"node_modules/font-awesome/css/font-awesome.min.css"
],
"assets": [
"src/assets",
"src/favicon.ico",
"node_modules/font-awesome/fonts"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"demo-e2e": {
"root": "",
"sourceRoot": "",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "./protractor.conf.js",
"devServerTarget": "demo:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"e2e/tsconfig.e2e.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "demo",
"schematics": {
"@schematics/angular:component": {
"prefix": "app",
"styleext": "scss"
},
"@schematics/angular:directive": {
"prefix": "app"
}
}
}
Ok,
Clarifying Abann's solution. You must use the long form for assets outside the sourceRoot
. I do think the documentation could be much more clear on that. It states
You can use this extended configuration to copy assets from outside your project. For instance, you can copy assets from a node package:
But really, it should say you must use
"assets": [
"src/assets",
"src/favicon.ico",
{
"glob": "*",
"input": "node_modules/font-awesome/fonts",
"output": "assets/fonts/"
}
],
Where assets/fonts/
is the path you probably configured in your SASS/SCSS file's $fa-font-path
variable override.
Edit 1
Okay try this:
"assets": [
{"glob": "**/*", "input": "./node_modules/youpackage", "output": "/where_you_want_theasset/"}
]
reference: https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/asset-configuration.md
Original answer: since it helped me(all my assets are in src)
I got the same error after updating,
try adding the root of your app to the angular.json
for me the sourceRoot and root are the same
"root": "src",
"sourceRoot": "src",
like so:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"demo": {
"root": "src",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
changing sourceRoot to '.' seems to have resolved this and allowed me to compile, and a superficial test shows everything working. not confident that this won't introduce other unintended consequences though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With