Skip to content

fix(view): treat names ending in '.' as extensionless - #7411

Closed
CSTRSK wants to merge 1 commit into
expressjs:masterfrom
CSTRSK:fix/view-dot-extension
Closed

fix(view): treat names ending in '.' as extensionless#7411
CSTRSK wants to merge 1 commit into
expressjs:masterfrom
CSTRSK:fix/view-dot-extension

Conversation

@CSTRSK

@CSTRSK CSTRSK commented Aug 8, 2026

Copy link
Copy Markdown

Fixes #7350

res.render('index.') / app.render('index.') threw a synchronous, opaque TypeError [ERR_INVALID_ARG_VALUE] from require(''), instead of the usual helpful Failed to lookup view error.

Root cause

path.extname('index.') returns '.', which is truthy — so the "no extension → use default engine" fallback in lib/view.js was skipped. this.ext stayed '.' and this.ext.slice(1) became '', so require('') was called and threw synchronously, bypassing the render callback entirely.

Change

Normalize ext === '.' to '' at the top of the View constructor. The default-engine fallback then applies, and lookup fails cleanly through the normal callback path:

app.render('index.', (err) => { ... })
// Before: synchronous TypeError (callback never invoked)
// After:  err = Failed to lookup view "index." in views directory "..."

This also covers app.set('view engine', ...) setups, exactly as reported.

Tests

Added a regression test in test/app.render.js. Full suite passes: 1153 passing (+1 new), eslint clean.

path.extname('index.') returns '.', which is truthy, so the
'no extension -> use default engine' fallback was skipped and
this.ext.slice(1) became '', causing require('') to throw an
opaque TypeError synchronously.

Normalize ext === '.' to '' so the default engine applies and
lookup fails with the usual 'Failed to lookup view' error.
@krzysdz

krzysdz commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #7351

@krzysdz krzysdz marked this as a duplicate of #7351 Aug 8, 2026
@krzysdz krzysdz closed this Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

res.render()/app.render() throws opaque TypeError for a view name ending in "."

2 participants