Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Broken compatibility with new keystone next.config.js template #333

Closed
Francoois opened this issue Jun 26, 2023 · 5 comments
Closed

Broken compatibility with new keystone next.config.js template #333

Francoois opened this issue Jun 26, 2023 · 5 comments

Comments

@Francoois
Copy link

Francoois commented Jun 26, 2023

In @keystone-6/core 5.3.2 "./___internal-do-not-use-will-break-in-patch/admin-ui/next-config" was removed and replaced by content generated from packages/core/src/admin-ui/templates/next-config.ts.

In @opensaas/keystone-nextjs-auth/src/templates/next-config.ts is :
const keystoneConfig = require('@keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/next-config').config;
It takes precedence over keystone.ts config and produce following error :

- error Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './___internal-do-not-use-will-break-in-patch/admin-ui/next-config' is not defined by "exports" in /cms/node_modules/@keystone-6/core/package.json
    at new NodeError (node:internal/errors:399:5)
    at exportsNotFound (node:internal/modules/esm/resolve:361:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:697:9)
    at resolveExports (node:internal/modules/cjs/loader:567:36)
    at Module._findPath (node:internal/modules/cjs/loader:636:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1063:27)
    at /cms/node_modules/@keystone-6/core/node_modules/next/dist/server/require-hook.js:189:36
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Should we import the template from Keystone ?

@Francoois
Copy link
Author

Simply replacing next.config.js is a fix :

In project root/admin/next.config.js :

const nextConfig = {
    typescript: {
      ignoreBuildErrors: true,
    },
    eslint: {
      ignoreDuringBuilds: true,
    },
    experimental: {
      appDir: false,
    },
    // We use transpilePackages for the custom admin-ui pages in the ./admin folder
    // as they import ts files into nextjs
    transpilePackages: ['../../admin'],
    basePath: '/admin' 
  }
  
  module.exports = nextConfig

In keystone.ts :

ui : {
    getAdditionalFiles: [
        async () => [
                {
						mode: 'copy',
						inputPath: Path.resolve('./admin/next.config.js'),
						outputPath: 'next.config.js',
					}
            ]
    ]
}

But then I have what I think is a next version error :

- error Error: Cannot find module 'next/dist/server/future/route-modules/route-module.js'
Require stack:
- /ks-project/.keystone/admin/.next/server/pages/_document.js
- /ks-project/node_modules/@keystone-6/core/node_modules/next/dist/server/require.js
- /ks-project/node_modules/@keystone-6/core/node_modules/next/dist/build/index.js
- /ks-project/node_modules/@keystone-6/core/scripts/cli/dist/keystone-6-core-scripts-cli.cjs.dev.js
- /ks-project/node_modules/@keystone-6/core/scripts/dist/keystone-6-core-scripts.cjs.dev.js
- /ks-project/node_modules/@keystone-6/core/scripts/dist/keystone-6-core-scripts.cjs.js
- /ks-project/node_modules/@keystone-6/core/bin/cli.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at /ks-project/node_modules/@keystone-6/core/node_modules/next/dist/server/require-hook.js:189:36
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at ../route-module (/ks-project/.keystone/admin/.next/server/pages/_document.js:82:18)
    at __webpack_require__ (/ks-project/.keystone/admin/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///../../node_modules/@keystone-6/core/node_modules/next/dist/server/future/route-modules/pages/module.js:20:22)
    at ../../node_modules/@keystone-6/core/node_modules/next/dist/server/future/route-modules/pages/module.js (/ks-project/.keystone/admin/.next/server/pages/_document.js:72:1)
    at __webpack_require__ (/ks-project/.keystone/admin/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///../../node_modules/@keystone-6/core/node_modules/next/dist/build/webpack/loaders/next-route-loader/index.js?page=%2F_document&absolutePagePath=private-next-pages%2F_document&preferredRegion=&middlewareConfig=e30%3D!:16:108)
    at ../../node_modules/@keystone-6/core/node_modules/next/dist/build/webpack/loaders/next-route-loader/index.js?page=%2F_document&absolutePagePath=private-next-pages%2F_document&preferredRegion=&middlewareConfig=e30%3D! (/ks-project/.keystone/admin/.next/server/pages/_document.js:32:1)
    at __webpack_require__ (/ks-project/.keystone/admin/.next/server/webpack-runtime.js:33:42)
    at __webpack_exec__ (/ks-project/.keystone/admin/.next/server/pages/_document.js:172:39)
    at /ks-project/.keystone/admin/.next/server/pages/_document.js:173:28
    at Object.<anonymous> (/ks-project/.keystone/admin/.next/server/pages/_document.js:176:3)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at requirePage (/ks-project/node_modules/@keystone-6/core/node_modules/next/dist/server/require.js:156:12)
    at /ks-project/node_modules/@keystone-6/core/node_modules/next/dist/server/load-components.js:64:65
    at async Promise.all (index 0)
    at async loadComponentsImpl (/ks-project/node_modules/@keystone-6/core/node_modules/next/dist/server/load-components.js:63:33)
    at async DevServer.findPageComponentsImpl (/ks-project/node_modules/@keystone-6/core/node_modules/next/dist/server/next-server.js:772:36) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/ks-project/.keystone/admin/.next/server/pages/_document.js',
    '/ks-project/node_modules/@keystone-6/core/node_modules/next/dist/server/require.js',
    '/ks-project/node_modules/@keystone-6/core/node_modules/next/dist/build/index.js',
    '/ks-project/node_modules/@keystone-6/core/scripts/cli/dist/keystone-6-core-scripts-cli.cjs.dev.js',
    '/ks-project/node_modules/@keystone-6/core/scripts/dist/keystone-6-core-scripts.cjs.dev.js',
    '/ks-project/node_modules/@keystone-6/core/scripts/dist/keystone-6-core-scripts.cjs.js',
    '/ks-project/node_modules/@keystone-6/core/bin/cli.js'
  ],
  page: '/auth/signin'
}

I'm investigating to make the versions match

@Francoois
Copy link
Author

Francoois commented Jun 27, 2023

Updating next to "next": "13.3.0", used by latest Keystone version fixed this error.
Not a keystone-nextjs-auth issue so I guess we can close it.
But we probably should do something about first ___internal-do-not-use import problem

@borisno2
Copy link
Member

Hey @Francoois thanks for logging this issue. You are correct, a recent change in Keystone has broken how this package adds a custom path to Keystone - something which has now also been added to Keystone see - keystonejs/keystone#8545

The way this package handles the next-auth session is also broken with later versions of next-auth (4.19.1 is the latest I have tested that works) (see my comment on #320)

With the, somewhat unknown, future impacts of the upcoming @auth/nextjs (AKA next-auth 5?) it is looking tricky to retrofit the way this package is currently working to make it work with newer versions of 'next-auth - it would most likely require a fairly extensive architecture of this package.

With this in mind, I created a PR over on the keystone repo that adds an example of using next-auth directly, without the use of this package, which has now been merged. You can check it out here keystonejs/keystone#8582 - this also has the added benefit of opening up the full power of next-auth with this like credentials and adapters, as well as adding your own custom callbacks.

I am still open to reviewing a PR if you think there is value in the package supporting the latest version of keystone, but not the latest of next-auth.
Thanks!

@Francoois
Copy link
Author

Thank you @borisno2 for your feedbacks, I understand better. It is probably a good idea to interact directly with next-auth.
Has examples/custom-session-next-auth been tested with custom basePath ?

@borisno2
Copy link
Member

borisno2 commented Jul 3, 2023

No worries @Francoois yes, it all will work with basePath

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants