question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

makeSchema's outputs/contextType .ts files need to be replaced with .js in production

See original GitHub issue

In the tutorial here: https://nexusjs.org/docs/getting-started/tutorial/chapter-adding-mutations-to-your-api#wire-up-the-context

…the following example is given:

  outputs: {
    typegen: join(__dirname, '..', 'nexus-typegen.ts'),
    schema: join(__dirname, '..', 'schema.graphql')
  },
  contextType: {                                    // 1
    module: join(__dirname, "./context.ts"),        // 2
    export: "ContextModule",                        // 3
  },

When TypeScript files are compiled to JavaScript, references to nexus-typegen.ts and ./context.ts need to be replaced with nexus-typegen.js and ./context.js , otherwise those files won’t be found. Here’s a suggestion on what it can be changed to:

  const ext = process.env.NODE_ENV === 'production' ? 'js' : 'ts';

  outputs: {
    typegen: join(__dirname, '..', `nexus-typegen.${ext}`),
    schema: join(__dirname, '..', 'schema.graphql'),
  },
  contextType: {
    module: join(__dirname, `./context.${ext}`),
    export: 'Context',
  },

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
miguelc1221commented, Jun 11, 2021

ran into a similar issue, using tsc to compile and it can’t find the ./context.ts in the dist folder, my solution was to generate the typegen before compiling when in dev but still need the above solution @chrishoermann suggested. Dropping the extension doesn’t seem to work .......dist/src/api/context for the type context does not exist

1reaction
santialbocommented, Feb 5, 2021

Nexus generates a typescript types file on development which should be compiled by typescript, there’s no need to change the extension on the output configuration. About the contextType, just drop the extension as you would do when you use import on your ts files.

  outputs: {
    typegen: join(__dirname, '..', `nexus-typegen.ts`),
    schema: join(__dirname, '..', 'schema.graphql'),
  },
  contextType: {
    module: join(__dirname, `./context`),
    export: 'Context',
  },
Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Migrating from JavaScript - TypeScript
The first step is to rename one of your .js files to .ts . If your file uses JSX, you'll need to rename...
Read more >
About "*.d.ts" in TypeScript - Stack Overflow
The "d.ts" file is used to provide typescript type information about an API that's written in JavaScript. The idea is that you're using...
Read more >
How to Add TypeScript to a JavaScript Project - freeCodeCamp
At first it can be used just as JS with .ts files and weird import lines. In this strategy, we will be compiling...
Read more >
Configuring TypeScript compiler - inDepthDev
TypeScript files are compiled into JavaScript using TypeScript compiler. ... Suppose, we want to compile all files in the project directory except for...
Read more >
JavaScript developer reference for Azure Functions
Each function has a folder with its own code file (.js) and binding ... To assign an output using return , change the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found