Trying to create a production build with Payload CMS Error

default discord avatar
callistusa
7 months ago
13

So i have been experimenting a lot with payload CMS, i am trying to produce a production build where i can inject environment variables



I stated with the blog template



Sorry i am not that familiar with GraphQL to dive into this but definitely feels like a schema issue or some component i am missing this is my logs error, anyone encountered this


cms-payload-1  | [23:39:01] INFO (payload): Connected to Mongo server successfully!
cms-payload-1  | [23:39:01] INFO (payload): Starting Payload...
cms-payload-1  | /home/node/node_modules/payload/node_modules/graphql/jsutils/devAssert.js:12
cms-payload-1  |     throw new Error(message);
cms-payload-1  |           ^
cms-payload-1  |
cms-payload-1  | Error: Expected JSON to be a GraphQL type.
cms-payload-1  |     at devAssert (/home/node/node_modules/payload/node_modules/graphql/jsutils/devAssert.js:12:11)
cms-payload-1  |     at new GraphQLList (/home/node/node_modules/payload/node_modules/graphql/type/definition.js:349:32)
cms-payload-1  |     at /home/node/node_modules/payload/dist/graphql/schema/withOperators.js:18:27
cms-payload-1  |     at Array.reduce (<anonymous>)
cms-payload-1  |     at withOperators (/home/node/node_modules/payload/dist/graphql/schema/withOperators.js:15:27)
cms-payload-1  |     at buildWhereInputType (/home/node/node_modules/payload/dist/graphql/schema/buildWhereInputType.js:48:43)
cms-payload-1  |     at /home/node/node_modules/payload/dist/collections/graphql/init.js:126:79
cms-payload-1  |     at Array.forEach (<anonymous>)
cms-payload-1  |     at initCollectionsGraphQL (/home/node/node_modules/payload/dist/collections/graphql/init.js:60:38)
cms-payload-1  |     at registerSchema (/home/node/node_modules/payload/dist/graphql/registerSchema.js:58:24)
cms-payload-1  |
cms-payload-1  | Node.js v18.14.1


Any insights or help would be greatly appreciated

  • discord user avatar
    dribbens
    Payload Team
    7 months ago

    I haven't been able to reproduce your issue.


    If you have some reproduction steps I'd like to try them to see what is going.


    Assuming you don't need GraphQL at all, you can set

    graphQL.disable: true

    in your Payload config which should prevent this from happening if you just want to be unblocked.

  • default discord avatar
    callistusa
    7 months ago

    Hi @dribbens this is my

    payload-config.ts
    import { buildConfig } from 'payload/config';
    import path from 'path';
    import Categories from './collections/Categories';
    import Posts from './collections/Posts';
    import Tags from './collections/Tags';
    import Users from './collections/Users';
    import Media from './collections/Media';
    
    export default buildConfig({
      serverURL: 'http://localhost:3000',
      admin: {
        user: Users.slug,
      },
      collections: [
        Categories,
        Posts,
        Tags,
        Users,
        Media,
      ],
      typescript: {
        outputFile: path.resolve(__dirname, 'payload-types.ts')
      },
      graphQL: {
        schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
      },
    });


    This is my dockerfile


    # syntax=docker/dockerfile:1
    FROM node:18-alpine as base
    
    FROM base as builder
    
    WORKDIR /home/node
    COPY package*.json ./
    
    COPY . .
    RUN npm ci
    RUN npm run build
    
    FROM base as runtime
    
    ENV NODE_ENV=production
    
    WORKDIR /home/node
    COPY package*.json  ./
    
    RUN npm i --omit dev
    COPY --from=builder /home/node/dist ./dist
    COPY --from=builder /home/node/build ./build
    COPY --from=builder /home/node/src/generated-schema.graphql ./dist/generated-schema.graphql
    EXPOSE 3000
    
    CMD ["node", "dist/server.js"]


    After taking that

    graphQL

    piece of configuration then i get a different error


    cms-payload-1  | [23:42:11] INFO (payload): Connected to Mongo server successfully!
    cms-payload-1  | [23:42:11] INFO (payload): Starting Payload...
    cms-payload-1  | /home/node/node_modules/payload/node_modules/graphql/jsutils/devAssert.js:12
    cms-payload-1  |     at /home/node/node_modules/payload/dist/graphql/schema/withOperators.js:18:27
    cms-payload-1  |     at Array.reduce (<anonymous>)
    cms-payload-1  |     at withOperators (/home/node/node_modules/payload/dist/graphql/schema/withOperators.js:15:27)
    cms-payload-1  |     at buildWhereInputType (/home/node/node_modules/payload/dist/graphql/schema/buildWhereInputType.js:48:43)
    cms-payload-1  |     at /home/node/node_modules/payload/dist/collections/graphql/init.js:126:79cms-payload-1  |     at Array.forEach (<anonymous>)cms-payload-1  |     at initCollectionsGraphQL (/home/node/node_modules/payload/dist/collections/graphql/init.js:60:38)cms-payload-1  |     at registerSchema (/home/node/node_modules/payload/dist/graphql/registerSchema.js:58:24)
    cms-payload-1  |
    cms-payload-1  | Node.js v18.14.1


    Do you think it could be the node version? might give that a try, but seems like when registering the schema if falls over

  • discord user avatar
    dribbens
    Payload Team
    7 months ago

    We had some issues recently due to some version issues with some incompatibilities of different GraphQL dependencies. I think that is what you are up against here.



    I don't think it is your node version. Switching to

    yarn

    might fix this in the short term.



    This is the thread that makes me think it could be related

    https://github.com/payloadcms/payload/discussions/1856

    . Without digging in more I'm not sure.



    Feel free to open an issue on our Github too, we do bugfixes on Mondays each week and if this is anyone using npm for Payload then we need to address it.

  • default discord avatar
    callistusa
    7 months ago

    Ok will do, wouldnt have expected it to be an NPM issue but hopefully you can figure it out



        "overrides": {
            "graphql": ">15.7.0 <16.7.0"
         }


    That block and rebuilding the

    package-lock.json

    solved it



    There must be something in the dependency tree that is lower than 15.7.0 and is causing that incorrect string parsing

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.