{"record":{"id":"0e4cd55e19b53587","repo":"gatsbyjs/gatsby","slug":"createslice-is-only-available-in-gatsby-v5","errorCode":null,"errorMessage":"createSlice is only available in Gatsby v5","messagePattern":"createSlice is only available in Gatsby v5","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/redux/actions/restricted.ts","lineNumber":532,"sourceCode":"        type: `CREATE_SLICE`,\n        plugin,\n        payload: {\n          componentChunkName: generateComponentChunkName(\n            payload.component,\n            `slice`\n          ),\n          componentPath,\n          // note: we use \"name\" internally instead of id\n          name: payload.id,\n          context: payload.context || {},\n          updatedAt: Date.now(),\n        },\n        traceId,\n        componentModified,\n        contextModified,\n      }\n    } else {\n      throw new Error(`createSlice is only available in Gatsby v5`)\n    }\n  },\n  /**\n   * Declares URL Pattern that should be allowed to be used for Image or File CDN to prevent using of unexpected RemoteFile URLs.\n   *\n   * @availableIn [onPreInit, onPreBootstrap, onPluginInit, createSchemaCustomization]\n   *\n   * @param {string | string []} url URLPattern or Array of URL Patternss that should be allowed.\n   * URLPattern is a string that can contain wildcards (*) or parameter placeholders (e.g. :id).\n   * @example\n   * exports.onPreInit = ({ actions }) => {\n   *   actions.addRemoteFileAllowedUrl(`https://your-wordpress-instance.com/*`)\n   * }\n   */\n  addRemoteFileAllowedUrl: (\n    url: string | Array<string>,\n    plugin: IGatsbyPlugin,\n    traceId?: string","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/redux/actions/restricted.ts#L514-L550","documentation":"The createSlice action (slices are partial-hydration component boundaries introduced in Gatsby v5) is gated behind a version check; on Gatsby v4 and earlier the restricted action creator throws unconditionally because the slice machinery, redux slices state, and rendering pipeline do not exist. The throw sits in the else-branch of the version-gated createSlice implementation in restricted.ts.","triggerScenarios":"Calling actions.createSlice(...) (directly or via a plugin/theme that uses slices) while running Gatsby < 5.0.0. The action creator is defined but the v5 code path is not taken, so the else-branch throws.","commonSituations":"Installing a theme/plugin authored against Gatsby v5 (e.g. one calling createSlice in gatsby-node/gatsby-browser) into a project still on Gatsby v4; upgrading the theme but not the gatsby package; using a starter that targets v5 on an older lockfile.","solutions":["Upgrade the project to Gatsby v5: `npm i gatsby@latest` (and follow the v4->v5 migration guide for Node >= 18.15, React 18, etc.).","If you cannot upgrade, pin/downgrade the offending theme or plugin to a version that supports Gatsby v4 (no createSlice usage).","Remove or guard the createSlice call if it is in your own code and you are not on v5."],"exampleFix":"// before - gatsby-node.js on Gatsby v4\nexports.createPages = ({ actions }) => {\n  actions.createSlice({ id: `header`, component: require.resolve(`./src/slices/header`) })\n}\n// after - upgrade to Gatsby v5, or remove the call\n// package.json: \"gatsby\": \"^5.0.0\"","handlingStrategy":"validation","validationCode":"// Gate createSlice usage on the running Gatsby major version.\nconst gatsbyPkg = require('gatsby/package.json')\nconst major = Number(gatsbyPkg.version.split('.')[0])\nfunction safeCreateSlice(actions, args) {\n  if (major < 5) {\n    console.warn('createSlice skipped: requires Gatsby v5+')\n    return\n  }\n  return actions.createSlice(args)\n}","typeGuard":"function supportsSlices() {\n  const v = require('gatsby/package.json').version\n  return Number(v.split('.')[0]) >= 5\n}","tryCatchPattern":null,"preventionTips":["Keep your gatsby major version aligned with the themes/plugins you consume.","Read plugin peerDependencies before installing.","Lock Gatsby to a known major in package.json."],"tags":["createslice","version","gatsby-v5","plugin-api"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}