keystone
keystone copied to clipboard
Building static pages fails with prerendering errors - Cannot read properties of null (reading 'useContext')
Upgrade to @keystone-6/ui 2.0.0 (from 1.1.1), run keystone build
Expected: The Admin UI bundle builds successfully. Actual: Building static pages fails with the errors shown in the screenshot below.

Node version v16.15.1.
Update - upgrading to node version 18.3 (and regeneration of package-lock/node_modules) fixes the issue. If this is reproducible, can this be documented please? and also getting Unsupported Engine warnings when running npm install from Keystone with Node 18 because Keystone specifies Node version of 16.
Thanks!
Facing same issue
It looks like @keystone-6/ui package doesn't exist. Maybe you are using @keystone-ui/core or @keystone-6/core ?
If you provide package.json, we may find clues.
Thanks @u-ishii
Here are the dependencies from package.json.
"dependencies": {
"@keystone-6/core": "^2.0.0",
"typescript": "^4.5.4"
},
According to the docs, that should be all that's required to run Keystone - is that correct? In addition, this only started happening with Keystone 2.0.0, and with Node version < 18.
I have been trying to replicate but have been unable to using node v16.15.0
Have you tried deleting any package lock files and node_modules folders to ensure a fresh install of dependencies?
@isla-nye I couldn't reproduce it either.
According to the docs, that should be all that's required to run Keystone - is that correct?
Yes.
Looking at your error message, it seems that react path is incorrect.
Incorrect: .../cms/node_modules/@keystone-6/core/node_modules/react/...
Correct: .../cms/node_modules/react/...
IMO, you may have run npm link before.
It has already been commented, I expect it to be resolved by clearing node_modules.
After deleting node_modules and re-installing the app, I'm getting this in the console:
package.json
{
"name": "pmd-ks-api",
"version": "5.0.0",
"private": true,
"scripts": {
"dev": "keystone dev",
"start": "keystone start",
"build": "keystone build",
"postinstall": "keystone postinstall --fix"
},
"dependencies": {
"@keystone-6/cloudinary": "^3.0.0",
"@keystone-6/core": "^2.0.0",
"@keystone-6/fields-document": "^3.0.0",
"@opensaas/keystone-nextjs-auth": "^23.0.0",
"dotenv": "^10.0.0",
"nodemailer": "^6.4.17",
"postmark": "^3.0.11",
"slugify": "^1.6.5",
"typescript": "^4.5.2"
},
"engines": {
"node": "^14.15 || ^16.13"
},
"resolutions": {
"next": "^12.1.0"
},
"devDependencies": {
"@faker-js/faker": "^6.0.0-alpha.7"
}
}
Hey folks, got this issue resolved by switching from npm i to yarn install (removed node_modules and *.lock file).

met the same issue and resolved it by using the same react version. https://github.com/keystonejs/keystone/issues/2898#issuecomment-699130482
npm list react find the react version are using
same issue 😞
@kirandash try this solution #8553 . It works to me
@kirandash try this solution #8553 . It works to me
thanks for the suggestion. I just tried and still the same issue after forcing resolution.
@kirandash the suggestion also works for me.
Fresh starting a Keystone app with yarn create keystone-app will install the required dependencies and yarn dev will start the app. However visiting any page will throw an exception: Cannot read properties of null (reading 'useContext')
@josemf same issue here. node v18.15.0 with npm 9.5.0
Have the same error
Same here.
I have the same error