keystone
keystone copied to clipboard
Keystone CLI ignores tsconfig.json, absolute import paths break keystone build
Background
- Mentioned here https://github.com/keystonejs/keystone/issues/8143#issuecomment-1340931482
- Reported in slack https://keystonejs.slack.com/archives/C01STDMEW3S/p1682573272390949
Repro steps
@keystone-6/core 5.2.0- Have a
keystone.tswith 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
...
})
- Run
keystone devor 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?)
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'
}