graphql-nexus / nexus-plugin-prisma

Deprecated
MIT License
828 stars 118 forks source link

Cannot find name 'NexusPrisma' in Vercel build fail. Using nextjs. #977

Open codekcv opened 3 years ago

codekcv commented 3 years ago

I'm using nextjs 10 and the latest nexus-plugin-prisma, nexus schema. See: sc_2020-12-02-145739_409x352

Saw these, but last year's issue and doesn't work anymore. https://github.com/graphql-nexus/nexus-plugin-prisma/issues/531 https://github.com/graphql-nexus/nexus-plugin-prisma/issues/558

Error in vercel sc_2020-12-02-024432_585x132

my tsconfig: sc_2020-12-02-150012_499x454

dewildio commented 3 years ago

Hi @codekcv, could you share your file structure + how you're generating the typegen file please ?

GolfredoPerezFernandez commented 3 years ago

same here i use graphql-auth prisma example

canrozanes commented 3 years ago

I came across the same issue yesterday while trying to deploy the following example to heroku: https://github.com/prisma/prisma-examples/tree/latest/typescript/graphql-apollo-server

rushi444 commented 3 years ago

This fixed it for me. Try adding this to your NexusPrisma config, or point it wherever your generated folder is

plugins: [ nexusPrisma({ experimentalCRUD: true, outputs: { typegen: join( __dirname, 'generated/', 'typegen-nexus-plugin-prisma.d.ts' ), }, }), ],

mrpitch commented 3 years ago

@rushi444 thanks for pointing in the right direction.

I ran in the same error. Per default typegen-nexus-plugin-prisma.ts is generated under node_module/@types and this is not found during build. Adding the snipped @rushi444 provided fixed the build process.

But when loading /api/graphql I ran into this error message EROFS: read-only file system, unlink '/var/task/src/generated/typegen-nexus-plugin-prisma.ts'

I fixed this by adding shouldGenerateArtifacts: process.env.NODE_ENV === 'development', so the files are only created in development env. This is also in the docs

Here is my code

export default NexusSchema.makeSchema({ types, shouldGenerateArtifacts: process.env.NODE_ENV === 'development', plugins: [nexusPrisma({ experimentalCRUD: true, outputs: { typegen: path.join(process.cwd(), 'src', 'generated', 'typegen-nexus-plugin-prisma.ts') }, })], outputs: { schema: path.join(process.cwd(), 'src', 'generated', 'schema.graphql'), typegen: path.join(process.cwd(), 'src', 'generated', 'nexus.type.ts'), }, sourceTypes: { modules: [{ module: '@prisma/client', alias: 'PrismaClient' }], }, contextType: { module: path.join(process.cwd(), 'src/context.ts'), export: 'Context', }, })

M0hammedImran commented 3 years ago

I tried all the above suggested answers, nothing worked for me. The problem was not only in the option that were passed to the plugin(I guess) but also the build process.

The Only thing that fixed the bug was adding a "prebuild" script

"prebuild": "ts-node --compiler-options '{\"module\":\"CommonJS\"}' --transpile-only src/graphql/schema"

and copying and pasting @mrpitch answer

export const schema = makeSchema({
    types: { Query, User, Mutation },
    shouldGenerateArtifacts: process.env.NODE_ENV === 'development',
    plugins: [
        nexusPrisma({
            experimentalCRUD: true,
            outputs: {
                typegen: join(
                    process.cwd(),
                    'src',
                    'generated',
                    'typegen-nexus-plugin-prisma.ts',
                ),
            },
        }),
    ],
    outputs: {
        schema: join(process.cwd(), 'src', 'generated', 'schema.graphql'),
        typegen: join(process.cwd(), 'src', 'generated', 'nexus.type.ts'),
    },
    sourceTypes: {
        modules: [{ module: '@prisma/client', alias: 'PrismaClient' }],
    },
    contextType: {
        module: join(process.cwd(), 'src/graphql/context.ts'),
        export: 'Context',
    },
})
leungandrew commented 3 years ago

I was able to get the above to work making note that you need to have your generated folder committed into your repo. What the above is doing is simply having the server not produce the artifacts during the build process which I believe is where the file-system read error is coming from.

@rushi444 thanks for pointing in the right direction.

I ran in the same error. Per default typegen-nexus-plugin-prisma.ts is generated under node_module/@types and this is not found during build. Adding the snipped @rushi444 provided fixed the build process.

But when loading /api/graphql I ran into this error message EROFS: read-only file system, unlink '/var/task/src/generated/typegen-nexus-plugin-prisma.ts'

So the solution says that you generate locally first, commit the files, so the server does not generate them. I do find it strange that we need to add shouldGenerateArtifacts: process.env.NODE_ENV === 'development' to the makeSchema call even though the docs say the following:

  /**
     * Whether the schema & types are generated when the server starts. Default is !process.env.NODE_ENV ||
     * process.env.NODE_ENV === "development"
     */
    shouldGenerateArtifacts?: boolean

perhaps there's some ENV variables being set depending on which Vercel ENV you are building against..