Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typegen error: has no exported member 'QueryMode' or 'SortOrder' #1056

Open
0xsven opened this issue Feb 24, 2021 · 13 comments
Open

typegen error: has no exported member 'QueryMode' or 'SortOrder' #1056

0xsven opened this issue Feb 24, 2021 · 13 comments

Comments

@0xsven
Copy link

0xsven commented Feb 24, 2021

Since I have upgraded my dependencies to...

"@prisma/client": "^2.17.0",
"nexus-plugin-prisma": "^0.31.0"
"prisma": "^2.17.0"

... I am getting the following error when transpiling my app:

Generated Artifacts:
          TypeScript Types  ==> /api/nexus-typegen.ts
          GraphQL Schema    ==> /api/schema.graphql
nexus-typegen.ts:626:21 - error TS2694: Namespace '"/api/node_modules/.prisma/client/index"' has no exported member 'QueryMode'.

626   QueryMode: prisma.QueryMode
                        ~~~~~~~~~

nexus-typegen.ts:628:21 - error TS2694: Namespace '"/api/node_modules/.prisma/client/index"' has no exported member 'SortOrder'.

628   SortOrder: prisma.SortOrder
                        ~~~~~~~~~

My workaround is to downgrade prisma client like so:

"@prisma/client": "^2.14.0",
"nexus-plugin-prisma": "^0.31.0"
"prisma": "^2.17.0"

Somehow prisma client 2.15.0 introduced a change that breaks my build. Any ideas what I am missing?

@pudgereyem
Copy link

I ran into the same issue after upgrading from 2.13 to 2.17, but for me it was only SortOrder.

Possible underlying issue? (not sure)

The underlying issue seems to be that in the latest version of Prisma, SortOrder is no longer exported at the top level. It is exported under the namespace Prisma. Comparing 2.17 v.s 2.13 below.

2.17 - node_modules/.prisma/client/index.d.ts

export namespace Prisma {

  // ... a lot of stuff here

  export const SortOrder: {
    asc: 'asc',
    desc: 'desc'
  };

  export type SortOrder = (typeof SortOrder)[keyof typeof SortOrder]
}

2.13 - node_modules/.prisma/client/index.d.ts

// ..same as above, but also exports type SortOrder, mentioning that it is deprecated

/**
 * @deprecated Renamed to `Prisma.SortOrder`
 */
export type SortOrder = Prisma.SortOrder

Manual workaround

I can fix this by manually changing the generated file like below

export interface NexusGenEnums {
  SortOrder: Prisma.Prisma.SortOrder // <-- this fixes it
}

But that is not ideal.

@Akxe
Copy link

Akxe commented Mar 4, 2021

This workaround is what was recommended to me too by maintainers of Prisma. Also, I would like to point out, that the error is type-check error only and the code will still output working code, as such it can be safely ignored as long as builds outputs files.

@0xsven
Copy link
Author

0xsven commented Mar 5, 2021

This file is generated by the system. How would you permanently change it?

@Akxe
Copy link

Akxe commented Mar 5, 2021

@0xsven You don't... You have to edit it after every generation... We can only hope this will get fixed...

@lvauvillier
Copy link
Contributor

Another workaround is to set "skipLibCheck": true in your typescript compilerOptions.

@Akxe
Copy link

Akxe commented Mar 10, 2021

@jasonkuhrt Would you mind looking into this? It is currently breaking every server build (I had to create bash utility to replace prisma.SortOrder to prisma.Prisma.SortOrder...)

I know that you (as prisma) are working on a new plugin, but this will help in the meantime. it should be a simple fix :)

@ltnscp9028
Copy link

ltnscp9028 commented Mar 18, 2021

@0xsven @Akxe

You can solve this problem by changing the output of makeSchema.

typegen: path.join(__dirname.'/api/nexus-typegen.ts') -> typegen: path.join(__dirname.'/api/nexus-typegen.d.ts')

@0xsven
Copy link
Author

0xsven commented Mar 31, 2021

Generated Artifacts:
          TypeScript Types  ==> /api/nexus-typegen.d.ts
          GraphQL Schema    ==> /api/schema.graphql
nexus-typegen.ts:605:21 - error TS2694: Namespace '"/api/node_modules/.prisma/client/index"' has no exported member 'QueryMode'.

605   QueryMode: prisma.QueryMode
                        ~~~~~~~~~

nexus-typegen.ts:607:21 - error TS2694: Namespace '"/api/node_modules/.prisma/client/index"' has no exported member 'SortOrder'.

607   SortOrder: prisma.SortOrder
                        ~~~~~~~~~


Found 2 errors.

@ltnscp9028 doesnt work for me

@Akxe
Copy link

Akxe commented Mar 31, 2021

This package is basically archivated for now, use this workaround:

ts-node -r tsconfig-paths/register --transpile-only ./schema.ts && npx replace-in-file prisma.SortOrder prisma.Prisma.SortOrder **/nexus.generated.ts

Rename the file to your file and if multiple replacements must be made, copy the command twice... not great, but it will do the job for now.

@0xsven
Copy link
Author

0xsven commented Apr 1, 2021

This worked fine. Thank you!

"build:replace": "replace-in-file prisma.SortOrder prisma.Prisma.SortOrder **/nexus-typegen.ts && replace-in-file prisma.QueryMode prisma.Prisma.QueryMode **/nexus-typegen.ts",

@iki
Copy link

iki commented Jan 31, 2022

@Akxe @0xsven nice hack with replace-in-file, but it doesn't trigger when nexus is generated by the dev server on model/api change.

To use nexus-plugin-prisma with prisma above 2.14, we can override .prisma/client typescript module resolution and inject both QueryMode and SortOrder properties:

  "compilerOptions": {
    "paths": {
      ".prisma/client": ["utils/fix-prisma-client-for-nexus.ts"]
    }
  }
/* eslint-disable import/no-relative-packages */
import { Prisma } from '../../node_modules/.prisma/client';

export * from '../../node_modules/.prisma/client';

// Fix nexus-plugin-prisma using QueryMode/SortOrder moved in prisma 2.15
// See https://github.com/graphql-nexus/nexus-plugin-prisma/issues/1056

export type SortOrder = Prisma.SortOrder;
export type QueryMode = Prisma.QueryMode;

export const { SortOrder, QueryMode } = Prisma;

@chrishoermann
Copy link

I replaced the types in makeSchemas mapping property - works perfectly:

export const schema = makeSchema({
    // ... rest of makeSchema config

    mapping: {
      //...all custom scalars
      SortOrder: 'prisma.Prisma.SortOrder',
      QueryMode: 'prisma.Prisma.QueryMode',
    },
  },

@seanemmer
Copy link

Amazing fix @chrishoermann thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants