angular-cli: Angular CLI is giving error - Can't resolve '/assets/***sharedfonts/open-sans-v15-latin-300.woff2' after updated to Angular 10

Hi,

I just updated to Angular 10 and before this i was using Angular 9.1 and this was working fine in Angular 9.1 now angular cli is throwing error that Can't resolve '/assets/***sharedfonts/open-sans-v15-latin-300.woff2' image

If i remove the ~ then it is working fine on local server but it is not replacing relative path in styles.d17173f9650483347d45.css production css file.

So because of that i am getting error on production server if i remove ~ image

Previous Angular 9.1 styles.css production file angular cli was automatically adding my href (MyProject) in path image Angular 10 styles.css production file angular cli not adding my href (MyProject) in path image

Adding this ~ before /assets/ i got this answer from here Please help me what am i missing? Is there something i need to do?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16

Most upvoted comments

@ErVishalM, the recommended approach is to use either relative paths were the assets will be processed out-of-the-box by the build system or use root paths if you want to load assets which are not relative to your base-href where you will need to copy the assets manually using assets option.

@ErVishalM, having the base href inlined in the bundle when using root level paths ie paths starting with a / is non standard and is deprecated behaviour which will be removed in the future without a replacement.

Since version 9, the base href value is not included in the final css file unless opting in the deprecated behaviour mentioned above. See: https://github.com/angular/angular-cli/issues/14587. The rebaseRootRelativeCssUrls option is there to allow users enough time to transition away from needing a base href inlined in their stylesheet.

In most cases users should rely upon the build system to process and emit assets referenced in CSS.

Paths starting with ~/, ^/ etc… are Webpack specific features which we always encountered users not to rely upon as these are unsupported and might break in the future version without warning.

Hi @ErVishalM,

This is working as expected. When using root paths / together with baseHref. the base href value is not inlined as part of the resource path in the CSS files. This has also been the case for a number of previous versions. if you want the base href to be included you can opt-in the deprecated behaviour using the rebaseRootRelativeCssUrls option.

If you wish that processed assets are not placed in the root of dist folder you can use the resourcesOutputPath option.

More information about these options can be found: https://angular.io/cli/build

@ErVishalM, I’ll take a look on Monday.

@ErVishalM, without a reproduction and the needed information it’s hard to tell what’s happening.