keystone icon indicating copy to clipboard operation
keystone copied to clipboard

Keystone CLI ignores tsconfig.json, absolute import paths break keystone build

Open Thinkscape opened this issue 2 years ago • 1 comments

Background

  • Mentioned here https://github.com/keystonejs/keystone/issues/8143#issuecomment-1340931482
  • Reported in slack https://keystonejs.slack.com/archives/C01STDMEW3S/p1682573272390949

Repro steps

  1. @keystone-6/core 5.2.0
  2. Have a keystone.ts with config, that includes a relative path (or in any further imported files)

tsconfig.json

compilerOption: { 
  baseUrl: ".", 
  paths: { "@utils/*" : ["./src/utils/*"] }
}

keystone.ts

// works when relative
import lists from "../../my/file"

// doesn't work with Keystone CLI when absolute or mapped
import lists from "src/my/file"
import lists from "@utils/my/file"

import { config } from "@keystone-6/core";

export default config({
  lists
  ...
})
  1. Run keystone dev or any command that triggers keystone schema compilation

Expected

Keystone works.

Actual

✨ Starting Keystone
Error: Cannot find module 'src/my/file'
Require stack:
- /Users/thinkscape/app/platform/.keystone/config.js
- /Users/thinkscape/app/platform/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@opentelemetry+ap_lnbdhzifg6beqfjpgx5jf4wgeq/node_modules/@keystone-
...

That's probably because keystone has its own webpack and tsconfig config used just for schema compilation (and admin build?)

Thinkscape avatar May 02 '23 00:05 Thinkscape

This unfortunately also breaks with any modern npm packages that dropped support for CommonJS:

✨ Starting Keystone
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/thinkscape/product/platform/node_modules/.pnpm/[email protected]/node_modules/oauth4webapi/build/index.js from /Users/thinkscape/product/platform/.keystone/config.js not supported.
Instead change the require of index.js in /Users/thinkscape/product/platform/.keystone/config.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/thinkscape/product/platform/.keystone/config.js:347:21)
    at Object.loadBuiltConfig (/Users/thinkscape/product/platform/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@b_7eb2ravqfia3a4vzpclnhhpvlm/node_modules/@keystone-6/core/dist/loadConfig-ef94af3f.cjs.dev.js:42:32)
    at dev (/Users/thinkscape/product/platform/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@b_7eb2ravqfia3a4vzpclnhhpvlm/node_modules/@keystone-6/core/scripts/cli/dist/keystone-6-core-scripts-cli.cjs.dev.js:904:43) {
  code: 'ERR_REQUIRE_ESM'
}

Thinkscape avatar May 12 '23 01:05 Thinkscape