nodejs/node · error · ValueError
AddFileConfig: file "%s" not in project.
Error message
AddFileConfig: file "%s" not in project.
What it means
MSVSProject.AddFileConfig raises ValueError when the given relative path is not present in self.files_dict. The VisualStudioProject object only knows about files previously registered through AddFiles(); AddFileConfig is meant to attach a per-configuration FileConfiguration to an already-known file node. Passing a path that was never added (or that doesn't byte-match the stored key) is treated as a programming error in the project generation pipeline.
Source
Thrown at tools/gyp/pylib/gyp/MSVSProject.py:180
# TODO(rspangler) This also doesn't handle adding files to an existing
# filter. That is, it doesn't merge the trees.
def AddFileConfig(self, path, config, attrs=None, tools=None):
"""Adds a configuration to a file.
Args:
path: Relative path to the file.
config: Name of configuration to add.
attrs: Dict of configuration attributes; may be None.
tools: List of tools (strings or Tool objects); may be None.
Raises:
ValueError: Relative path does not match any file added via AddFiles().
"""
# Find the file node with the right relative path
parent = self.files_dict.get(path)
if not parent:
raise ValueError('AddFileConfig: file "%s" not in project.' % path)
# Add the config to the file node
spec = self._GetSpecForConfiguration("FileConfiguration", config, attrs, tools)
parent.append(spec)
def WriteIfChanged(self):
"""Writes the project file."""
# First create XML content definition
content = [
"VisualStudioProject",
{
"ProjectType": "Visual C++",
"Version": self.version.ProjectVersion(),
"Name": self.name,
"ProjectGUID": self.guid,
"RootNamespace": self.name,
"Keyword": "Win32Proj",
},View on GitHub (pinned to 1b2de5e052)
Solutions
- Call AddFiles([path]) with the identical path string before AddFileConfig(path, ...).
- Normalize both paths the same way (os.path.normpath or the project's existing helper) before lookup.
- Audit gyp source rules to confirm the file isn't being filtered out by 'sources!' exclusions before AddFileConfig runs.
- If the file is intentionally absent, skip the AddFileConfig call rather than configuring a phantom node.
Example fix
# before
proj.AddFileConfig('src/foo.cpp', 'Debug', attrs, tools)
# after
proj.AddFiles(['src/foo.cpp'])
proj.AddFileConfig('src/foo.cpp', 'Debug', attrs, tools) Defensive patterns
Strategy: validation
Validate before calling
def safe_add_file_config(proj, path, config, attrs=None, tools=None):
norm = os.path.normpath(path)
if norm not in proj.files_dict:
proj.AddFiles([norm])
proj.AddFileConfig(norm, config, attrs, tools) Type guard
def file_is_known(proj, path: str) -> bool:
return os.path.normpath(path) in proj.files_dict Try / catch
from gyp.MSVSProject import MSVSProject
try:
proj.AddFileConfig(path, config, attrs, tools)
except ValueError:
# file not added via AddFiles yet -> add then retry
proj.AddFiles([path])
proj.AddFileConfig(path, config, attrs, tools) Prevention
- Always call AddFiles([path]) with the exact string before AddFileConfig(path, ...).
- Normalize paths with the project's own helper so separators/casing match the stored key.
- Treat AddFileConfig as a per-config decorator on files already in the project, never as an inserter.
When it happens
Trigger: Calling proj.AddFileConfig(path, config, ...) before a corresponding proj.AddFiles([path]) for the exact same path string; using a path with a different separator ('\\' vs '/') or different casing than what AddFiles stored; removing a file from the spec then trying to configure it.
Common situations: Gyp emits an MSVS project and a generator/extension tries to set per-config attributes on a file that was filtered out of AddFiles (excluded by sources! rules); cross-platform path joining produces 'foo\bar.cpp' for AddFiles and 'foo/bar.cpp' for AddFileConfig.
Related errors
- expected string; got %r
- expected string list; got %r
- expected bool; got %r
- index value (%d) not in expected range [0, %d)
- value must be one of [0, 1, 2]; got %s
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/41abd897a2ceb196.
Report an issue: GitHub.