-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot import { runCommand } from 'nuxi' since 3.9.2 #331
Comments
Would you be able to provide a reproduction? 🙏 More infoWhy do I need to provide a reproduction?Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. What will happen?If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect. If How can I create a reproduction?We have a couple of templates for starting with a minimal reproduction: 👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz A public GitHub repository is also perfect. 👌 Please ensure that the reproduction is as minimal as possible. See more details in our guide. You might also find these other articles interesting and/or helpful: |
Start a new pull request in StackBlitz Codeflow. |
Hi. The See this example: https://github.com/unjs/docs/blob/main/src/cli.ts#L41 |
Hello! But wait, why? It was possible all the time since Nuxt 3.0.0, and I already built some websites utilizing this, so they run in build and making a snapshots via runCommand('generate'). Why should I not do it? It works perfectly?! |
I'm not sure to understand how it was supposed to work. CLI is used to itself build a Nuxt/Nitro application and generate etc. Importing CLI itself in runtime is not intended to be done (even if it was working before by any chance, it was chance!) If you would explain more context of your usecase (why you need a server route that itself runs generate command) and how you deploy such usage, i might be able to give an alternative solution. |
The idea is simple: If you run a nuxt website in To be able to directly import runCommand is the better alternative, otherwise I would need to spawn a child process with the same cli command. And side-effects are my problem anyways, so I would speak out for keeping the option, but maybe with a warning. But let me know why it's not intended to be available in runtime?! I think it's a plus to use these commands programmatically in routes. |
Thanks for explaining your use-case. As a much better alternative, I suggest you try the hybrid rendering with caching rules that is available in Nuxt 3. This method gives the flexibility of caching on demand and generating content from a CMS source and removing the limitations of traditional generate command. I explained before. CLI or non of Nuxt build dependencies (such as If finally you want to keep your architecture as-is (while I really would advice against), you have two options:
export default defineEventHandler(async (event) => {
// Use absolutely on YOUR OWN RISK!
const _pkg = 'nuxi';
const { runCommand } = await import(_pkg);
return true;
}); |
And thanks for going along with me :) The thing with hybrid rendering is that it needs a specific hosting (node). Reality strikes as not all my clients can do this, despite the fact that hosting in Germany (and probably EU) is a mess and still all about php… On the other hand if you use the system described above you can host the staging website on your own servers and deploy a statically generate website to any host or CDN, regardless of your clients IT infrastructure, and that's nice and easy. This works for me for quite some time now (~5years), already with Nuxt 2 I had a similar approach to scope with all the non-streamlined hosting-providers. I never had any major problems. If you change buildDirs and output.dirs regarding the process, then Thanks for the work-arounds, will use them on my very own risk! |
@pi0 Do you think that's something the Nitro Task API could "cover" later one? |
Actually... You can :) You can have hybrid rendering in ANY hosting and storage method that complies with your regulations. All you have to do is to configure Yes generate is sweet but it had enough limitations in the past that others made ISR and we made Nuxt 3 with hybrid rendering. If any time later you wanted to give it a try or had any specific concerns, feel free to reach me out via Discord (pi0). Nuxt Labs also has consulting services to help you on this path.
@manniL It seems tempting and a similar somehow but unfortunately No. Tasks API are still a "Runtime" API. Running a build-time CLI still shared same. We might think of a programmatic API that populates the hybrid rendering cache though using Tasks API but it is nothing we can't today with a protected route. But with upcoming Tasks API would be easier to do. |
I think there is a missunderstanding. I mean in an environment where it's not possible to run any node command, so not |
Hybrid rendering does not requires |
The only point I am trying to make is that it's nice to generate a static website from a website which runs in build, I think conceptually it is not contradictory that you have tools that are built to build an application and run inside this application. One can see this more as an |
You might use a pure Nitro server for this webhook handling which has not (Nuxt) default import protections like |
Environment
Darwin
v18.19.0
3.9.3
3.10.0
2.8.1
npm@10.2.3
-
-
-
-
Reproduction
import { runCommand } from 'nuxi'
https://stackblitz.com/edit/github-ebvksd?file=server%2Fapi%2Fgenerate.js
Describe the bug
Since Nuxt 3.9.2 I cannot import runCommand from nuxi anylonger.
Additional context
No response
Logs
The text was updated successfully, but these errors were encountered: