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.

Running a custom script each time Next app is recompiled during development

See original GitHub issue

Hi,

TLDR:

I want to run a custom script each time Next recompiles during development. I’m developing a Next app locally with now dev. Is there any place I define a command that should run each time the Next app is recompiled in response to a change in the codebase?

Details on why I want to do this below:

I’m using Next 9 with a GraphQL API served from pages/api/graphql.ts. I’m using apollo-server-micro, based on the example shown here: https://gist.github.com/mfellner/2119db3584023092d70118a8dabd146e

Additionally, I’m defining my schema for the server using a library called nexus. With nexus, each time the server starts, nexus will write a .ts file to the local filesystem. This file contains types which reflect the graphql schema of the server, enabling type checking in the resolvers of the server.

Here’s a line that configures where nexus generates this file: https://github.com/prisma/nexus/blob/develop/examples/apollo-fullstack/src/index.ts#L18

The nexus examples recommend using a library like ts-node-dev to run a server locally, which will automatically restart in response to any changes in the schema. Example here: https://github.com/prisma/nexus/blob/develop/examples/apollo-fullstack/package.json#L8

However, when developing through an api endpoint setup in Next, with apollo-server-micro, the server doesn’t ever “start”. As far as I understand, apollo-server-micro just exports a handler for use in lambdas.

As a result, there’s no point at which nexus autogenerates my types file.

I want to run the command to generate these types each time my Next app recompiles, so the type checking on my GraphQL resolvers always matches the latest changes to my GraphQL schema.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
liamdanielduffycommented, Aug 16, 2019

Hey @Timer!

Can you confirm whether or not, in general, there’s a way to tell Next to run a custom command each time it recompiles your code?

I actually did post the same question on Spectrum about 2 weeks back: https://spectrum.chat/next-js/general/running-a-custom-script-each-time-next-app-is-recompiled-during-development~23e051e5-d0a1-4d3b-9c9e-c1e354d40d30

I also posted it here, in case this wasn’t already an existing feature of the framework. I thought this issue might be turned into a ‘feature request’ ticket, incase there wasn’t an existing way to provide Next with a custom command to run during re-compilation.

Thank you for your help 😃

0reactions
balazsorban44commented, Jan 31, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running a custom script each time Next app is recompiled ...
I want to run a custom script each time Next recompiles during development. I'm developing a Next app locally with now dev ....
Read more >
Node NextJS app recompiling when running in dev = true mode
When I start the app in development mode npm wants to recompile the app even though all of the built components still exist....
Read more >
How to run scripts before every build on Next.js | Kontent.ai.
In this article, I'll explain some of the use-cases for having pre-build (or start-up) scripts, show how to implement them and run them ......
Read more >
Building and running an app | Apple Developer Documentation
During development, you build and run an app many times to test new features and eliminate bugs. Each time you build, Xcode analyzes...
Read more >
The React Scripts Start Command – Create-React-App NPM ...
The script generates the required files and folders to start the React application and run it on the browser. This allows you to...
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