{"record":{"id":"5efc1814a803c620","repo":"gatsbyjs/gatsby","slug":"the-namespace-parameter-passed-to-createnodeid-m","errorCode":null,"errorMessage":"The `namespace` parameter passed to createNodeId must be a String (got ${typeof namespace})","messagePattern":"The `namespace` parameter passed to createNodeId must be a String \\(got (.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/gatsby/src/utils/create-node-id.ts","lineNumber":44,"sourceCode":" * to make sure the id ends up being short, whatever the input size was.\n *\n * Note: UUID is relatively slow because it calls into the native crypto library to generate SHA-1 hashes.\n *       We do need the low collision rate of SHA-1 so we use a local (global) cache to speed up repetitive calls\n *\n * @param {String | Number} id - A string of arbitrary length\n * @param {String} namespace - Namespace to use for UUID\n *\n * @return {String} - UUID\n */\nexport function createNodeId(id: string | number, namespace: string): string {\n  if (typeof id === `number`) {\n    id = id.toString()\n  } else if (typeof id !== `string`) {\n    report.panic(\n      `The \\`id\\` parameter passed to createNodeId must be a String or Number (got ${typeof id})`\n    )\n  } else if (typeof namespace !== `string`) {\n    report.panic(\n      `The \\`namespace\\` parameter passed to createNodeId must be a String (got ${typeof namespace})`\n    )\n  }\n\n  let nsHash = unprefixedCache.get(namespace)\n  if (!nsHash) {\n    nsHash = uuidv5(namespace, seedConstant) as string\n    unprefixedCache.set(namespace, nsHash)\n  }\n\n  // Calling uuid is relatively expensive because it calls into crypto for sha1.\n  // We use a local map to cache calls with the same ns+id pair, which helps a lot.\n  let nsCache = namespacedCache.get(namespace)\n  if (!nsCache) {\n    nsCache = new Map()\n    namespacedCache.set(namespace, nsCache)\n  }\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/utils/create-node-id.ts#L26-L62","documentation":"createNodeId takes a namespace (typically the Gatsby createNodeId bound by createNodeFactory or passed as the second argument) used to scope UUID generation. The namespace must be a string. If it is undefined, null, or any non-string type, Gatsby panics. This check only runs when id is a string (the else-if chain).","triggerScenarios":"Calling createNodeId('some-id') without the second argument, or passing a non-string namespace. This happens when the bound createNodeId function from actions or gatsby-node context is not used, or when calling the raw createNodeId from gatsby/utils without a namespace.","commonSituations":"Importing createNodeId directly from gatsby/node-utils instead of using the one provided in actions.createNodeId (which has the namespace pre-bound). A source plugin that destructures incorrectly and loses the namespace binding. Passing undefined as namespace due to a variable not being set.","solutions":["Use actions.createNodeId(id) from sourceNodes/onCreateNode context -- Gatsby pre-binds the correct namespace.","If calling the raw utility, pass a valid string namespace: createNodeId(id, 'my-plugin-namespace').","Verify the namespace variable is defined before calling -- add a guard or default."],"exampleFix":"// before -- raw import loses namespace\nconst { createNodeId } = require('gatsby/utils')\nconst id = createNodeId('post-1') // namespace is undefined\n\n// after -- use actions-bound version\nexports.sourceNodes = ({ actions, createNodeId }) => {\n  const id = createNodeId('post-1') // namespace pre-bound\n}","handlingStrategy":"validation","validationCode":"// Validate namespace before calling createNodeId\nfunction validateCreateNodeIdNamespace(namespace) {\n  if (typeof namespace !== 'string') {\n    throw new Error('createNodeId namespace must be string, got ' + typeof namespace)\n  }\n}","typeGuard":"function isValidNamespace(ns) {\n  return typeof ns === 'string' && ns.length > 0\n}","tryCatchPattern":null,"preventionTips":["Use actions.createNodeId from the Gatsby context -- it pre-binds the namespace.","If calling the raw utility, always pass a string namespace explicitly.","Avoid importing createNodeId directly from internal paths."],"tags":["createnodeid","source-plugin","validation","namespace"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}