angular-cli: Build warnings after migrating to Angular 12.0.0 for external .css files `Unable to locate stylesheet`

Hi there!

After migrating my project to version 12.0.0, I get the following messages for external .css files when I issue the command ng build:

  • Generating index html…Unable to locate stylesheet: C:\myproject\ClientApp\dist\https:\somedomain\somefile.min.css

Also when running the command ng serve, I get the corresponding warning messages for the same files.

The references (there are two such files) are in the <head> section of my index.html

<link rel="stylesheet" href="https://somedomain/somefile.min.css">

The application is correctly compiling otherwise, and runs correctly.

Thanks a lot for your attention.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 16 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I just came here to report the same thing. All of our projects refer tot he same set of global styles at our organization so we add the following to the index.html of each project

<link rel="stylesheet" type="text/css" href="https://internalcdn.com/Apps/CSS/StyleSheet.css">

Now with Angular 12, we get this warning every time we build…

Unable to locate stylesheet: C:\dist\https:\internalcdn.com\Apps\CSS\StyleSheet.css

As @jlquijada stated, the resulting build is still correct and the site works as expected.

I’m having the same issue while using https://github.com/angular/universal Turning off inlineCriticalCss in ngExpressEngine options seems to work for me at least for SSR.

// server.ts
ngExpressEngine({
      bootstrap: AppServerModule,
      inlineCriticalCss: false
})

As far as I see it is caused by Critters:getCssAsset() - it’s trying to resolve external assets (ex. from CDN) on local path

 var normalizedPath = href.replace(/^\//, '');
                    var pathPrefix = (publicPath || '').replace(/(^\/|\/$)/g, '') + '/';
                    if (normalizedPath.indexOf(pathPrefix) === 0) {
                        normalizedPath = normalizedPath.substring(pathPrefix.length).replace(/^\//, '');
                    }
                    var filename_1 = path.resolve(outputPath, normalizedPath);
                    var sheet_1;
                    var _temp5 = _catch(function () {
                        return Promise.resolve(_this3_1.readFile(filename_1)).then(function (_this3$readFile) {
                            sheet_1 = _this3$readFile;
                        });
                    },

@maxisam, your issue is slightly different, see: https://github.com/angular/universal/issues/2019.

Note: deployUrl is deprecated and is recommended to replace it with baseHref and APP_BASE_HREF instead.