keystone icon indicating copy to clipboard operation
keystone copied to clipboard

Building static pages fails with prerendering errors - Cannot read properties of null (reading 'useContext')

Open isla-nye opened this issue 3 years ago • 19 comments

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.

image

Node version v16.15.1.

isla-nye avatar Jun 10 '22 22:06 isla-nye

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!

isla-nye avatar Jun 13 '22 11:06 isla-nye

Facing same issue

ScottAgirs avatar Jun 15 '22 08:06 ScottAgirs

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.

u-ishii avatar Jun 17 '22 17:06 u-ishii

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.

isla-nye avatar Jun 20 '22 10:06 isla-nye

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?

borisno2 avatar Jun 21 '22 05:06 borisno2

@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.

u-ishii avatar Jun 22 '22 15:06 u-ishii

After deleting node_modules and re-installing the app, I'm getting this in the console:

Screen Shot 2022-06-24 at 6 22 31 PM

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"
  }
}

ScottAgirs avatar Jun 24 '22 22:06 ScottAgirs

Hey folks, got this issue resolved by switching from npm i to yarn install (removed node_modules and *.lock file).

ScottAgirs avatar Jun 28 '22 22:06 ScottAgirs

image

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

marsk6 avatar Aug 28 '22 08:08 marsk6

same issue 😞

kirandash avatar May 07 '23 08:05 kirandash

@kirandash try this solution #8553 . It works to me

uafrontender avatar May 08 '23 21:05 uafrontender

@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 avatar May 09 '23 09:05 kirandash

@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 avatar May 09 '23 18:05 josemf

@josemf same issue here. node v18.15.0 with npm 9.5.0

tawsbob avatar May 14 '23 02:05 tawsbob

Have the same error

westtrade avatar May 17 '23 08:05 westtrade

Same here.

longlostnick avatar May 19 '23 04:05 longlostnick

I have the same error

Alexandra-Haynes avatar Jun 09 '23 20:06 Alexandra-Haynes