makeSchema's outputs/contextType .ts files need to be replaced with .js in production
See original GitHub issueIn 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:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 thetypegen
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
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.