keystone
keystone copied to clipboard
Keystone npm/yarn post install fail when keystone is in folder
Bug report
I get this error if my keystone.ts file is not in root. In my case it was in keystone folder as I wanted to start keystone in forked process.
> keystone-next postinstall
Error: Cannot find module 'D:\project-root\my-project\keystone'
D:\project-root\my-project
is root folder for my project.
Describe the bug
Keystone is trying to run post install to generate prisma schema etc which fails due to no keystone.ts file found in the root.
To Reproduce
move all keystone related files into keystone
or any other folder
create index.js in root and spawn/fork keystone to run in the separate process.
Expected behaviour
npm install
or yarn
should not fail
keystone should look for keystone.ts file or ask if it is missing. better behavior would be to allow config in package.json or in .keystonerc file
System information
- OS: Windows
Thanks for this report @gautamsi, we'll look into this.
I realize that I was using a postinstall
script for generating prisma schema using keystone cli. For this there is no cwd option, it fails if it did not find the keystone.ts
file in current directory
at the moment all three files MUST BE inside the "cwd"
schema.graphql
schema.prisma
keystone.ts
if you change the "cwd" before for example to src
you got ugly src/node_modules
folders
to have a param for the package scripts would be awesome!
my current workaround: I generate "ts-forward-file" and two symlinks (and hide these files at my editor)
keystone.ts
import keystone from './src/keystone'
export default keystone
symlinks (windows)
mklink /h schema.graphql src\@generated\schema.graphql
mklink /h schema.prisma src\@generated\schema.prisma
prisma:warn The postinstall script automatically ran `prisma generate` and did not find your `prisma/schema.prisma`.
If you have a Prisma schema file in a custom path, you will need to run
`prisma generate --schema=./path/to/your/schema.prisma` to generate Prisma Client.
If you do not have a Prisma schema file yet, you can ignore this message.
Is there any workaround for custom admin pages? The docs state that you have to put them in admin/pages
at the root. (I tried adding admin/pages/index.ts
and importing/re-export pages from src/admin/pages
, but it didn't pick up on it.)
Otherwise, I got it working:
I referenced the keystone.ts file in a src
subdirectory in a similar way as @crazyx13th mentioned, and that worked fine:
export { default } from './src/keystone'
And I just left schema.graphql
and schema.prisma
at the root (I didn't want them to be in src
anyway, since they're generated files).
This is quite a complex problem, rooted in where the assumed built keystone configuration is, and where that should be generated.
We do want to help users customize their own esbuild entrypoints
to resolve this type of problem in the future.
That said, for now, this is a feature request and, if still wanted, can be re-opened as a GitHub discussion.
See 42e0bd5bb0141a1100477d70aab84645509caef7 for an example of how we might approach this, a CLI parameter is another option