nodejs/node · error · TypeError
no loader for this environment specified
Error message
no loader for this environment specified
What it means
Raised by Environment._load_template (jinja2 environment.py) when a template is requested (get_template / select_template / {% include %} / {% extends %}) but the Environment was constructed without a loader. A loader (FileSystemLoader, PackageLoader, DictLoader, etc.) is what maps template names to sources; without one there is nothing to load from.
Source
Thrown at tools/inspector_protocol/jinja2/environment.py:797
exc_type, exc_value, tb = traceback.standard_exc_info
reraise(exc_type, exc_value, tb)
def join_path(self, template, parent):
"""Join a template with the parent. By default all the lookups are
relative to the loader root so this method returns the `template`
parameter unchanged, but if the paths should be relative to the
parent template, this function can be used to calculate the real
template name.
Subclasses may override this method and implement template path
joining here.
"""
return template
@internalcode
def _load_template(self, name, globals):
if self.loader is None:
raise TypeError('no loader for this environment specified')
cache_key = (weakref.ref(self.loader), name)
if self.cache is not None:
template = self.cache.get(cache_key)
if template is not None and (not self.auto_reload or
template.is_up_to_date):
return template
template = self.loader.load(self, name, globals)
if self.cache is not None:
self.cache[cache_key] = template
return template
@internalcode
def get_template(self, name, parent=None, globals=None):
"""Load a template from the loader. If a loader is configured this
method asks the loader for the template and returns a :class:`Template`.
If the `parent` parameter is not `None`, :meth:`join_path` is called
to get the real template name before loading.
View on GitHub (pinned to 1b2de5e052)
Solutions
- Construct the Environment with a loader: `Environment(loader=FileSystemLoader('tpl'))`.
- If you only render inline templates, use env.from_string(...) instead of get_template.
- For package templates, use PackageLoader or PackageLoader('pkg','templates').
Example fix
# before
env = Environment()
env.get_template('x.html')
# after
from jinja2 import FileSystemLoader
env = Environment(loader=FileSystemLoader('tpl'))
env.get_template('x.html') Defensive patterns
Strategy: validation
Validate before calling
def can_load(env) -> bool:
return env.loader is not None
# construct with a loader:
# Environment(loader=FileSystemLoader('tpl')) Type guard
def has_loader(env) -> bool:
return getattr(env, 'loader', None) is not None Try / catch
try:
env.get_template(name)
except TypeError as e:
if 'no loader' in str(e):
raise SystemExit('configure a loader on the Environment')
raise Prevention
- Construct Environments with a loader whenever you will call get_template.
- Use env.from_string for inline-only rendering.
- Centralize Environment creation so the loader is always set.
When it happens
Trigger: Building `Environment()` with no loader and then calling `env.get_template('x.html')`; using from_string-only env for inline templates but later calling get_template; a loader that was passed as a positional misconfiguration.
Common situations: Quick prototypes that render only from_string and forget the loader; refactoring that moved the loader into a conditional branch that didn't run; copying an Environment setup that omitted the loader kwarg.
Related errors
- none of the templates given were found: %s
- The environment was not created with async mode enabled.
- Template module attribute is unavailable in async mode
- Loop length for some iterators cannot be lazily calculated i
- extended multiple times
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/717e3355a2bbbe28.
Report an issue: GitHub.