graphql-nexus / nexus

Code-First, Type-Safe, GraphQL Schema Construction
https://nexusjs.org
MIT License
3.4k stars 275 forks source link

Cannot find context file after building for production in typescript #1038

Open zaniluca opened 2 years ago

zaniluca commented 2 years ago

Issue

I'm trying to deploy to my VPS, after performing the build command and trying to run the transpiled code I get this error:

 Error: Root typing path "...\api\dist\src\graphql\context.ts" for the type "context" does not exist

Code

The problem for what i can tell is because after the build is completed it cannot resolve the context.ts file marked as the context source file in the schema:

// dist/src/graphql/schema.ts
export const schema = makeSchema({
  types: [allTypes],
  outputs: 
    typegen: join(__dirname, "./generated/nexus-typegen/index.d.ts"),
    schema: join(__dirname, "./generated/schema.graphql"),
  },
  ...
  contextType: {
    module: join(__dirname, "./context.ts"), // <-----
    export: "Context",
  },
  ...
});

After building the code the transpiled javascript is this:

// dist/src/graphql/schema.js
exports.schema = (0, nexus_1.makeSchema)({
    ...
    outputs: {
        typegen: (0, path_1.join)(__dirname, "./generated/nexus-typegen/index.d.ts"),
        schema: (0, path_1.join)(__dirname, "./generated/schema.graphql"),
    },
    ...
    contextType: {
        module: (0, path_1.join)(__dirname, "./context.ts"),  // <----
        export: "Context",
    },

});

Temporary solution

The temporary solution I came up with is simply to comment out the contextType property of the schema so that at least the code runs when deployed.

Versions

I'm using:

"nexus": "^1.1.0"
"nexus-prisma": "^0.35.0"
"ts-node": "^10.4.0"
"typescript": "^4.5.4"
"prisma": "^3.8.1"
ivoilic commented 2 years ago

This is a duplicate of #841, however the provided solution there didn't seem to work for me.