gatsbyjs/gatsby · error · Error
createSlice is only available in Gatsby v5
Error message
createSlice is only available in Gatsby v5
What it means
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.
Source
Thrown at packages/gatsby/src/redux/actions/restricted.ts:532
type: `CREATE_SLICE`,
plugin,
payload: {
componentChunkName: generateComponentChunkName(
payload.component,
`slice`
),
componentPath,
// note: we use "name" internally instead of id
name: payload.id,
context: payload.context || {},
updatedAt: Date.now(),
},
traceId,
componentModified,
contextModified,
}
} else {
throw new Error(`createSlice is only available in Gatsby v5`)
}
},
/**
* Declares URL Pattern that should be allowed to be used for Image or File CDN to prevent using of unexpected RemoteFile URLs.
*
* @availableIn [onPreInit, onPreBootstrap, onPluginInit, createSchemaCustomization]
*
* @param {string | string []} url URLPattern or Array of URL Patternss that should be allowed.
* URLPattern is a string that can contain wildcards (*) or parameter placeholders (e.g. :id).
* @example
* exports.onPreInit = ({ actions }) => {
* actions.addRemoteFileAllowedUrl(`https://your-wordpress-instance.com/*`)
* }
*/
addRemoteFileAllowedUrl: (
url: string | Array<string>,
plugin: IGatsbyPlugin,
traceId?: stringView on GitHub (pinned to 8b06340921)
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.
Example fix
// before - gatsby-node.js on Gatsby v4
exports.createPages = ({ actions }) => {
actions.createSlice({ id: `header`, component: require.resolve(`./src/slices/header`) })
}
// after - upgrade to Gatsby v5, or remove the call
// package.json: "gatsby": "^5.0.0" Defensive patterns
Strategy: validation
Validate before calling
// Gate createSlice usage on the running Gatsby major version.
const gatsbyPkg = require('gatsby/package.json')
const major = Number(gatsbyPkg.version.split('.')[0])
function safeCreateSlice(actions, args) {
if (major < 5) {
console.warn('createSlice skipped: requires Gatsby v5+')
return
}
return actions.createSlice(args)
} Type guard
function supportsSlices() {
const v = require('gatsby/package.json').version
return Number(v.split('.')[0]) >= 5
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- generateImageSource must be a function
- GatsbySortAndAggrCodemod: GraphQL syntax error in query: ${
- Plugins creating nodes can not set data on the reserved fiel
- A plugin tried to update a node field that it doesn't own:
- An ID must be provided when creating or setting job
AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13).
Data as JSON: /api/errors/0e4cd55e19b53587.
Report an issue: GitHub.