NG04002: Cannot match any routes. URL Segment: 'favicon.ico'
jdbenn opened this issue ยท 4 comments
๐ Bug report
What modules are related to this issue?
- builders
- common
- [x ] express-engine
Is this a regression?
Yes, the previous version in which this bug was not present was: Angular 13Description
Upgraded to Angular 15 and the I get a RuntimeError: NG04002: Cannot match any routes. URL Segment: 'favicon.ico' on the express server. The express.static did not change with this upgrade:
๐ฌ Minimal Reproduction
server.ts
export function app() {
const server = express();
const distFolder = join(process.cwd(), 'dist/browser');
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';
const LAZY_MODULE_MAP =require('./src/main.server');
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
server.engine('html', ngExpressEngine({
bootstrap: AppServerModule,
}));
server.set('view engine', 'html');
server.set('views', distFolder);
// Example Express Rest API endpoints
// app.get('/api/**', (req, res) => { });
// Serve static files from /browser
server.get('*.*', express.static(distFolder, {
maxAge: '1y'
}));
// All regular routes use the Universal engine
server.get('*', (req, res) => {
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
});
return server;
}
yarn dev:ssr
๐ฅ Exception or Error
RuntimeError: NG04002: Cannot match any routes. URL Segment: 'favicon.ico'
๐ Your Environment
Angular CLI: 15.1.5
Node: 16.13.0
Package Manager: yarn 1.22.19
OS: win32 x64
Angular: 15.1.4
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, platform-server, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1501.5
@angular-devkit/build-angular 15.1.5
@angular-devkit/core 15.1.5
@angular-devkit/schematics 15.1.5
@angular/cdk 14.2.7
@angular/cli 15.1.5
@nguniversal/builders 15.1.0
@nguniversal/express-engine 15.1.0
@schematics/angular 15.1.5
rxjs 7.5.7
typescript 4.8.4
webpack 5.75.0
Hi,
I have also seen this error in my angular universal application. In my case favicon.ico is not loading from below code
server.get('*.*', express.static(distFolder, { maxAge: '1y' }));
but the favicon.ico request is going to below code
server.get('*', (req, res) => { res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] }); });
Thanks,
This is probably related to this issue: angular/angular#50787
The problem here is likely that you do not have a favicon.ico
which is causing the express.static
middleware to fail and substantially fallback to ngExpressEngine
which will also fail as it's not a known route.
You can disable this behaviour by adding fallthrough: false
to express.static
.
For more information see: https://expressjs.com/en/resources/middleware/serve-static.html
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.