Skip to content

Fix res.render() TypeError for view names ending in '.'#7382

Closed
driphtyio wants to merge 1 commit into
expressjs:masterfrom
driphtyio:master
Closed

Fix res.render() TypeError for view names ending in '.'#7382
driphtyio wants to merge 1 commit into
expressjs:masterfrom
driphtyio:master

Conversation

@driphtyio

Copy link
Copy Markdown

Fix #7350

Problem

res.render('index.') / app.render('index.') throws an opaque TypeError: The argument 'id' must be a non-empty string from require('') instead of returning a proper "Failed to lookup view" error through the callback.

Root cause

path.extname('index.') returns '.', which is truthy, so Express skips the "no extension → use default engine" fallback. this.ext.slice(1) becomes '', leading to require('').

Fix

When path.extname() returns exactly '.' (name ends with a dot), normalize this.ext to empty string so Express falls through to the standard no-extension handling. This produces the expected "Failed to lookup view" error instead of an opaque TypeError.

Fixes expressjs#7350

path.extname('index.') returns '.' which is truthy, so Express
skips the no-extension fallback and calls require(''), throwing
an opaque TypeError. Normalize '.' to empty string so the
standard lookup error is returned through the callback.
@krzysdz

krzysdz commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #7351

@krzysdz krzysdz marked this as a duplicate of #7351 Jul 16, 2026
@krzysdz krzysdz closed this Jul 16, 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