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.

Try to support running with ts-node

See original GitHub issue

ts-node does not auto-import types from include because there’s a notable performance penalty to doing so. As a result when running with ts-node the types file generated by Nexus’ typegen option are not available, and thus any custom scalar method or plugin method will result in a type error. And ts-node still seems to be the de-facto way to run TypeScript in development.

ts-node does offer a way to support generated TypeScript definitions. By adding a folder to typeRoots. However for that to work the generated typescript definitions need to be structured as type packages not loose type definition files.

It would be really nice if using Nexus in development would work smoothly with ts-node without needing to use --files, manually include the generated types with /// <reference in every single schema definition file you write, or setup a complex alternative to ts-node.

I think this might be possible if Nexus generated its type definition files in a type package structure.

I’m not entirely certain how Nexus’ generated types work. But I think it’s possible that the declare global may not work with the type package structure.

One theoretical alternative I could think of would be to fake something like a @nexus/schema/generated module. The real @nexus/schema/generated module file would not export any types, or alternatively it would just re-export the current interfaces that are global declared interfaces so that @nexus/schema can import them from @nexus/schema/generated instead of relying on them being global. Then if a project opts-in to typegen exporting a type package instead of a loose type definition file Nexus can generate a {typegenRoot}/@nexus/schema/generated.d.ts and instead of declare global Nexus can export things inside of declare module "@nexus/schema/generated" blocks and this will theoretically override the @nexus/schema/generated with the generated types that Nexus needs.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonkuhrtcommented, Nov 9, 2020

@Weakky had a theory (we never verified) that node_modules/@types/* was special cased by and/or VSCode/TS Language Server such that changes under that directory were picked up and affected TS typings state consistently.

I’ve definitely seen the issues you’re referring to though. I actually had a rough time the other week on a demo project and it was using node_modules/@types in that case. But that was an exception in my experience.

So many moving parts and changing versions of tools integrating 🙈.

0reactions
alchemyjamiecommented, Jul 11, 2022

Im experiencing a similar issue. I have my nexus types being outputted to node_modules/@types/nexus-typegen/index.d.ts, and have "typeRoots": ["./typings", "./node_modules/@types" in my tsconfig.json, but am not able to reference nexus types such as NexusGenFieldTypes

Read more comments on GitHub >

github_iconTop Results From Across the Web

Try to support running with ts-node · Issue #513 - GitHub
As a result when running with ts-node the types file generated by Nexus' typegen option are not available, and thus any custom scalar...
Read more >
How To Run TypeScript Scripts with ts-node - DigitalOcean
In this article you will learn how to run TypeScript scripts without the hassle of manually transpiling.
Read more >
ts-node - npm
ts -node is a TypeScript execution engine and REPL for Node.js. It JIT transforms TypeScript into JavaScript, enabling you to directly execute ...
Read more >
Getting Started with Executing TypeScript files in ts-node
1. Run the following command to launch the TypeScript REPL. You'll be given a REPL prompt, as you see below, where you can...
Read more >
Troubleshooting | ts-node - TypeStrong · GitHub
When you try to run this code, node 12 will throw a SyntaxError . To fix this, you must switch to "target": "es2019"...
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