nexus-plugin-prisma: Cannot find name 'NexusPrisma'

when running type check on my project I get the following:

$ tsc
generated/typegen.ts:29:11 - error TS2304: Cannot find name 'NexusPrisma'.

29     crud: NexusPrisma<TypeName, 'crud'>
             ~~~~~~~~~~~

generated/typegen.ts:30:12 - error TS2304: Cannot find name 'NexusPrisma'.

30     model: NexusPrisma<TypeName, 'model'>
              ~~~~~~~~~~~

Should these be imported from somewhere? or am I missing a step?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 20 (1 by maintainers)

Most upvoted comments

@radicand thanks, but it didn’t work for me. I temporarily fixed it by generating the types again to the folder, where nexus.ts lives.

I had to adjust nexusPrismaPlugin like this:

  plugins: [
    nexusPrismaPlugin({
      // Fixes the Cannot find NexusPrisma issue
      outputs: { typegen: __dirname + '/generated/index.ts' },
    }),
  ],

I ended up here after googling the same type error and I would like to mention that when NODE_ENV is set to production, type files are not generated. In the case where you need to compile typescript on production environment, you need to specify shouldGenerateArtifacts option like below.

 plugins: [
    nexusSchemaPrisma({
     // Generate typefiles on any occasions 
      shouldGenerateArtifacts : true,
      outputs : {
        typegen: __dirname + '/generated/typegen-nexus-plugin-prisma.d.ts'
      }
    })
  ],

I had to run the following to get this solved:

  1. Generate Photon client again:
prisma2 generate
  1. Run application so makeSchema(…) gets called again which takes care of updating the typegen.ts file

  2. Wait for VSCode to pick up the changes … this sometimes takes a few seconds (restart may help)

@jorgenskogas ok, changed that to

outputs: { typegen: path.join(process.cwd(), 'pages', 'api', 'generated', 'typegen-nexus-plugin-prisma.d.ts') }

And it seems to be working fine now.

@bogdancss this fixed it for me (if you test this locally, clean/delete your node_modules first)

import { makeSchema } from '@nexus/schema';
import { nexusSchemaPrisma } from 'nexus-plugin-prisma/schema';
import * as types from './types';

export const schema = makeSchema({
	types,
-	plugins: [nexusSchemaPrisma()],
+	plugins: [nexusSchemaPrisma({ outputs: { typegen: __dirname + '/generated/typegen-nexus-plugin-prisma.d.ts' } })],
	outputs: {
		schema: __dirname + '/generated/schema.graphql',
		typegen: __dirname + '/generated/nexus.ts',
	},
	typegenAutoConfig: {
		sources: [
			{
				source: '@prisma/client',
				alias: 'client',
			},
			{
				source: require.resolve('./context'),
				alias: 'Context',
			},
		],
		contextType: 'Context.Context',
	},
});

@cypcz I ran into this because I had added in my tsconfig.json a definition for types: ["node"]. After removing the types key, it compiled fine. If you need your types defined there, there is likely a way to make this work too - but that’s a pointer in the right direction at least.

I’m experiencing the same issue.NexusPrisma type should be coming from node_modules/@types/nexus-prisma-typegen/index.d.ts. It is there: image

But generated nexus.ts still can’t find it. image

Any suggestion, please?