keystone icon indicating copy to clipboard operation
keystone copied to clipboard

Keystone npm/yarn post install fail when keystone is in folder

Open gautamsi opened this issue 3 years ago • 6 comments

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

gautamsi avatar May 07 '21 22:05 gautamsi

Thanks for this report @gautamsi, we'll look into this.

bladey avatar May 10 '21 03:05 bladey

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

gautamsi avatar May 10 '21 08:05 gautamsi

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!

crazyx13th avatar Jul 01 '21 15:07 crazyx13th

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

grafik

crazyx13th avatar Jul 02 '21 08:07 crazyx13th

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.

theskillwithin avatar Sep 01 '21 14:09 theskillwithin

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).

mbrowne avatar Sep 09 '21 20:09 mbrowne

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.

dcousens avatar Nov 14 '23 01:11 dcousens

See 42e0bd5bb0141a1100477d70aab84645509caef7 for an example of how we might approach this, a CLI parameter is another option

dcousens avatar Nov 14 '23 01:11 dcousens