keystonejs / keystone

The superpowered headless CMS for Node.js — built with GraphQL and React
https://keystonejs.com
MIT License
9.3k stars 1.16k forks source link

Error after upgrading to @keystone/core 6.1.0 (from 5.7.2) #9229

Closed rburgst closed 4 months ago

rburgst commented 4 months ago

After upgrading to the latest version I am getting the following error

error - Error: Cannot find module 'next/dist/shared/lib/constants.js'
Require stack:
- /Users/rainer/git/private/turnen/sports-keystone-next/server/.keystone/admin/.next/server/pages/_document.js
- /Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/node_modules/next/dist/server/require.js
- /Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/node_modules/next/dist/build/index.js
- /Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/scripts/cli/dist/keystone-6-core-scripts-cli.cjs.dev.js
- /Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/scripts/dist/keystone-6-core-scripts.cjs.dev.js
- /Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/scripts/dist/keystone-6-core-scripts.cjs.js
- /Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/bin/cli.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at /Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/node_modules/next/dist/server/require-hook.js:108:36
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at ../shared/lib/constants (/Users/rainer/git/private/turnen/sports-keystone-next/server/.keystone/admin/.next/server/pages/_document.js:82:18)
    at __webpack_require__ (/Users/rainer/git/private/turnen/sports-keystone-next/server/.keystone/admin/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///../../node_modules/@keystone-6/core/node_modules/next/dist/pages/_document.js:33:20)
    at ../../node_modules/@keystone-6/core/node_modules/next/dist/pages/_document.js (/Users/rainer/git/private/turnen/sports-keystone-next/server/.keystone/admin/.next/server/pages/_document.js:22:1)
    at __webpack_require__ (/Users/rainer/git/private/turnen/sports-keystone-next/server/.keystone/admin/.next/server/webpack-runtime.js:33:42)
    at __webpack_exec__ (/Users/rainer/git/private/turnen/sports-keystone-next/server/.keystone/admin/.next/server/pages/_document.js:122:39)
    at /Users/rainer/git/private/turnen/sports-keystone-next/server/.keystone/admin/.next/server/pages/_document.js:123:28
    at Object.<anonymous> (/Users/rainer/git/private/turnen/sports-keystone-next/server/.keystone/admin/.next/server/pages/_document.js:126:3)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at requirePage (/Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/node_modules/next/dist/server/require.js:156:12)
    at /Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/node_modules/next/dist/server/load-components.js:64:65
    at async Promise.all (index 0)
    at async loadComponentsImpl (/Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/node_modules/next/dist/server/load-components.js:63:33)
    at async DevServer.findPageComponentsImpl (/Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/node_modules/next/dist/server/next-server.js:765:36) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/rainer/git/private/turnen/sports-keystone-next/server/.keystone/admin/.next/server/pages/_document.js',
    '/Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/node_modules/next/dist/server/require.js',
    '/Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/node_modules/next/dist/build/index.js',
    '/Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/scripts/cli/dist/keystone-6-core-scripts-cli.cjs.dev.js',
    '/Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/scripts/dist/keystone-6-core-scripts.cjs.dev.js',
    '/Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/scripts/dist/keystone-6-core-scripts.cjs.js',
    '/Users/rainer/git/private/turnen/sports-keystone-next/server/node_modules/@keystone-6/core/bin/cli.js'
  ],
  page: '/signin'
}

Any idea what could have caused this? I could not really find a migration guide.

Node 20.14.0

I tried to look at the web site for an upgrade guide but it seams that the site is broken, I get only 404 pages.

These are my dependencies

  "resolutions": {
    "@types/react": "18.3.1",
    "@types/react-dom": "18.3.1",
    "graphql": "16.8.1"
  },
  "dependencies": {
    "@graphql-tools/schema": "^10.0.4",
    "@keystone-6/auth": "^8.0.0",
    "@keystone-6/core": "^6.1.0",
    "@keystone-6/fields-document": "^9.0.0",
    "@prisma/client": "5.13.0",
    "@tailwindcss/forms": "^0.5.7",
    "dataloader": "^2.2.2",
    "graphql": "16.9.0",
    "graphql-depth-limit": "^1.1.0",
    "nodemailer": "^6.9.14",
    "pino": "^9.3.1",
    "pino-pretty": "^11.2.1",
    "prisma": "5.13.0",
    "rambda": "^9.2.1",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "tailwindcss": "^3.4.6",
    "tiny-invariant": "^1.3.3",
    "typesafe-utils": "^1.16.2",
    "write-excel-file": "^2.0.3"
  },
  "devDependencies": {
    "@graphql-ts/schema": "^0.6.0",
    "@next/eslint-plugin-next": "^14.2.5",
    "@types/graphql-depth-limit": "^1.1.6",
    "@types/http-errors": "^2.0.4",
    "@types/jest": "^29.5.12",
    "@types/nodemailer": "^6.4.15",
    "@typescript-eslint/eslint-plugin": "^7.17.0",
    "@typescript-eslint/parser": "^7.17.0",
    "autoprefixer": "^10.4.19",
    "cuid": "^3.0.0",
    "dotenv": "^16.4.5",
    "dotenv-cli": "^7.4.2",
    "eslint": "^8.57.0",
    "eslint-config-preact": "^1.4.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-import-resolver-node": "^0.3.9",
    "eslint-plugin-compat": "^6.0.0",
    "eslint-plugin-cypress": "^3.3.0",
    "eslint-plugin-editorconfig": "^4.0.3",
    "eslint-plugin-filenames": "^1.3.2",
    "eslint-plugin-import": "^2.29.1",
    "eslint-plugin-jest": "^28.6.0",
    "eslint-plugin-react": "^7.35.0",
    "eslint-plugin-react-hooks": "^4.6.2",
    "eslint-plugin-simple-import-sort": "^12.1.1",
    "eslint-plugin-sonarjs": "^1.0.4-alpha.1",
    "eslint-plugin-sort-keys-fix": "^1.1.2",
    "jest": "^29.7.0",
    "postcss": "^8.4.39",
    "prettier": "^3.3.3",
    "rehype-document": "^7.0.3",
    "rehype-format": "^5.0.0",
    "rehype-stringify": "^10.0.0",
    "remark-cli": "^12.0.1",
    "remark-gfm": "^4.0.0",
    "remark-preset-lint-consistent": "^6.0.0",
    "remark-preset-lint-recommended": "^7.0.0",
    "remark-rehype": "^11.1.0",
    "remark-toc": "^9.0.0",
    "to-vfile": "^8.0.0",
    "ts-jest": "^29.2.3",
    "tsx": "^4.16.2",
    "typescript": "^5.5.4",
    "unified": "^11.0.5"
  },
  "packageManager": "yarn@4.2.2",
  "engines": {
    "node": "^20.14.0"
  },
  "engineStrict": true,
  "volta": {
    "node": "20.14.0",
    "yarn": "1.22.17"
  }
rburgst commented 4 months ago

Also note that when I tried to create a fresh keystone app (to check what should be changed) I am getting this problem

yarn create keystone-app@latest
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 1s 215ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 1s 306ms

/Users/rainer/.yarn/berry/cache/meow-npm-9.0.0-8b2707248e-8.zip/node_modules/meow/index.js:15
delete require.cache[__filename];
                     ^

TypeError: Cannot convert undefined or null to object
    at Object.<anonymous> (/Users/rainer/.yarn/berry/cache/meow-npm-9.0.0-8b2707248e-8.zip/node_modules/meow/index.js:15:22)
    at loadCJSModule (node:internal/modules/esm/translators:262:3)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:297:7)
    at ModuleJob.runSync (node:internal/modules/esm/module_job:212:17)
    at require (node:internal/modules/esm/translators:247:9)
    at Object.<anonymous> (/Users/rainer/.yarn/berry/cache/create-keystone-app-npm-9.0.1-4993dfb452-8.zip/node_modules/create-keystone-app/dist/create-keystone-app.cjs.dev.js:5:12)
    at loadCJSModule (node:internal/modules/esm/translators:262:3)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:297:7)
    at ModuleJob.runSync (node:internal/modules/esm/module_job:212:17)
    at require (node:internal/modules/esm/translators:247:9)

Node.js v20.14.0
dcousens commented 4 months ago

Hi @rburgst,

error - Error: Cannot find module 'next/dist/shared/lib/constants.js'

Can you verify that your next version is the same as Keystone's?

dcousens commented 4 months ago

the site is broken, I get only 404 pages.

Fwiw, this was resolved yesterday with https://github.com/keystonejs/keystone/pull/9227, unintentionally broken in https://github.com/keystonejs/keystone/pull/9220

rburgst commented 4 months ago

Hm, after downgrading, I upgraded again today and the problem is gone, when I do

yarn why next
└─ @keystone-6/core@npm:6.1.0
   └─ next@npm:13.3.2 [ed1e6] (via npm:^13.3.0 [ed1e6])

this is the next version I am getting. Note that last time, I did delete my .keystone and node_modules folder (however, I did not delete the lock file).

The only relevant difference I could spot between my old package.json and the current working one is

    "graphql": "16.9.0",

instead of 16.8.0. However, that couldnt really be responsible for the next problem IMHO.

dcousens commented 4 months ago

Maybe related https://github.com/keystonejs/keystone/issues/8181 and https://github.com/keystonejs/keystone/issues/7625#issuecomment-1163815289