{"record":{"id":"9f16b2e0b8445615","repo":"nodejs/node","slug":"multiple-module-definition-files-in-one-target-ta","errorCode":null,"errorMessage":"Multiple module definition files in one target, target %s lists multiple .def files: %s","messagePattern":"Multiple module definition files in one target, target (.+?) lists multiple \\.def files: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/generator/msvs.py","lineNumber":1402,"sourceCode":"\n\ndef _GetDisabledWarnings(config):\n    return [str(i) for i in config.get(\"msvs_disabled_warnings\", [])]\n\n\ndef _GetModuleDefinition(spec):\n    def_file = \"\"\n    if spec[\"type\"] in [\n        \"shared_library\",\n        \"loadable_module\",\n        \"executable\",\n        \"windows_driver\",\n    ]:\n        def_files = [s for s in spec.get(\"sources\", []) if s.endswith(\".def\")]\n        if len(def_files) == 1:\n            def_file = _FixPath(def_files[0])\n        elif def_files:\n            raise ValueError(\n                \"Multiple module definition files in one target, target %s lists \"\n                \"multiple .def files: %s\" % (spec[\"target_name\"], \" \".join(def_files))\n            )\n    return def_file\n\n\ndef _ConvertToolsToExpectedForm(tools):\n    \"\"\"Convert tools to a form expected by Visual Studio.\n\n    Arguments:\n      tools: A dictionary of settings; the tool name is the key.\n    Returns:\n      A list of Tool objects.\n    \"\"\"\n    tool_list = []\n    for tool, settings in tools.items():\n        # Collapse settings with lists.\n        settings_fixed = {}","sourceCodeStart":1384,"sourceCodeEnd":1420,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/generator/msvs.py#L1384-L1420","documentation":"Raised as a ValueError by _GetModuleDefinition when a linkable target (shared_library, loadable_module, executable, windows_driver) lists more than one .def file among its sources. A module definition file controls linker exports; multiple .def files are ambiguous and MSVS/link cannot consume more than one, so gyp refuses to pick.","triggerScenarios":"A target of a linkable type whose 'sources' array contains two or more entries ending in '.def'. The list comprehension collecting def_files yields length > 1 at msvs.py:1397.","commonSituations":"Globbing sources with a pattern that catches multiple .def files; merging two libraries' sources into one target without dropping the redundant .def; platform-specific .def files for both architectures left in the same source list.","solutions":["Keep only one .def file in the target's sources; remove or exclude the others.","Use conditions to select the correct .def per platform/configuration rather than listing all.","If multiple exports are needed, merge them into a single .def file."],"exampleFix":"// before\n'sources': ['a.cc', 'exports_x86.def', 'exports_x64.def']\n// after\n'sources': ['a.cc'],\n'conditions': [\n  ['OS==\"win\" and target_arch==\"x64\"', { 'sources': ['exports_x64.def'] }],\n  ['OS==\"win\" and target_arch==\"ia32\"', { 'sources': ['exports_x86.def'] }]\n]","handlingStrategy":"validation","validationCode":"def_files = [s for s in spec.get('sources', []) if s.endswith('.def')]\nif len(def_files) > 1:\n    raise ValueError(f\"multiple .def files: {def_files}\")","typeGuard":"def has_single_def(spec) -> bool:\n    defs = [s for s in spec.get('sources', []) if s.endswith('.def')]\n    return len(defs) <= 1","tryCatchPattern":null,"preventionTips":["Keep at most one .def file per linkable target.","Use conditions to select platform-specific .def files."],"tags":["gyp","msvs","module-definition","def-file","windows","linker"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}