{"record":{"id":"393af30bd50808d4","repo":"balderdashy/sails","slug":"e-invalid-hook-name","errorCode":"E_INVALID_HOOK_NAME","errorMessage":"Found hook: `HOOK_NAME`, in `node_modules/`, but a hook with that identity already exists in `api/hooks/`. The hook defined in your `api/hooks/` folder will take precedence.","messagePattern":"Found hook: `HOOK_NAME`, in `node_modules/`, but a hook with that identity already exists in `api/hooks/`\\. The hook defined in your `api/hooks/` folder will take precedence\\.","errorType":"console","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"lib/hooks/moduleloader/index.js","lineNumber":551,"sourceCode":"              return memo;\n            }\n\n            // Allow overriding core hooks\n            if (sails.hooks[hookName]) {\n              sails.log.verbose('Found hook: `'+hookName+'` in `node_modules/`.  Overriding core hook w/ the same identity...');\n            }\n\n            // If we have a hook in api/hooks with this name, throw an error\n            if (hooks[hookName]) {\n              var err = (function (){\n                var msg =\n                'Found hook: `' + hookName + '`, in `node_modules/`, but a hook with that identity already exists in `api/hooks/`. '+\n                'The hook defined in your `api/hooks/` folder will take precedence.';\n                var err = new Error(msg);\n                err.code = 'E_INVALID_HOOK_NAME';\n                return err;\n              })();\n              sails.log.warn(err);\n              return memo;\n            }\n\n            // Load the hook code\n            var hook = require(path.resolve(sails.config.appPath, 'node_modules', identity));\n\n            // Set its config key (defaults to the hook name)\n            hook.configKey = (sails.config.installedHooks && sails.config.installedHooks[identity] && sails.config.installedHooks[identity].configKey) || hookName;\n\n            // Add this to the list of hooks to load\n            memo[hookName] = hook;\n\n            return memo;\n          }, {}));//</_.reduce() + _.extend()>\n\n          return bindToSails(cb)(null, hooks);\n\n        } catch (e) { return cb(e); }","sourceCodeStart":533,"sourceCodeEnd":569,"githubUrl":"https://github.com/balderdashy/sails/blob/7b76422cc27823df033572bdda5c4910a68b697f/lib/hooks/moduleloader/index.js#L533-L569","documentation":"E_INVALID_HOOK_NAME warning from the moduleloader: a hook was found in node_modules/ whose identity collides with a hook already defined in the app's api/hooks/ folder. It is not fatal — Sails logs a warning and the api/hooks/ version takes precedence; the node_modules hook is skipped.","triggerScenarios":"Installing an npm package whose name matches a custom hook in api/hooks/ (e.g. api/hooks/myhook and node_modules/myhook), or scaffolding a custom hook with the same name as an installed sails hook package.","commonSituations":"Moving a hook from api/hooks/ into an npm package (or vice versa) and leaving both copies; installing a package that coincidentally shares a hook identity.","solutions":["Remove one of the duplicate hooks (delete api/hooks/<name> or uninstall the node_modules package).","If the api/hooks/ version is intended, ignore the warning or uninstall the npm duplicate.","Rename one of the hooks so identities differ.","Confirm which copy is actually loading via sails.hooks to avoid stale-behavior confusion."],"exampleFix":"// before: both api/hooks/auth/ and node_modules/auth exist\n// after\nnpm uninstall auth  # keep the api/hooks/auth copy in control","handlingStrategy":"validation","validationCode":"const fs = require('fs'), path = require('path');\nconst custom = fs.existsSync(path.join('api/hooks', hookName));\nconst inNm = fs.existsSync(path.join('node_modules', hookName));\nif (custom && inNm) console.warn('Duplicate hook identity: ' + hookName);","typeGuard":"function isHookNameCollision(names) { const set = new Set(names); return names.length !== set.size ? [...set] : null; }","tryCatchPattern":null,"preventionTips":["When npm-ifying a custom hook, delete the api/hooks copy.","Compare api/hooks/ dir names with sails.config.hookOverrides/installed packages.","Inspect sails.hooks after lift to confirm which copy loaded."],"tags":["hooks","duplicate","moduleloader","sails"],"backgroundTag":"duplicate-hook-identity","analyzedSha":"7b76422cc27823df033572bdda5c4910a68b697f","analyzedAt":"2026-09-01T04:01:57.104Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}