nuxt/cli

nuxi `prepare` or `build` hangs

mrniamster opened this issue ยท 37 comments

Environment


  • Operating System: Darwin
  • Node Version: v20.5.1
  • Nuxt Version: 3.7.0
  • CLI Version: 3.7.0
  • Nitro Version: 2.6.1
  • Package Manager: npm@9.8.0
  • Builder: -
  • User Config: experimental, css, ssr, nitro, app, modules, devtools
  • Runtime Modules: @pinia/nuxt@0.4.11, @nuxt/content@2.7.2, @vueuse/nuxt@10.4.0, @vuestic/nuxt@1.0.14
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-khexbq?file=package.json

Describe the bug

image

Doing a npm install stucks at the above position , doing a npx nuxi upgrade --force fixes the issue,
Conflicting during deploying .

image

Additional context

No response

### Logs

+ npm install

npm WARN ERESOLVE overriding peer dependency

npm WARN While resolving: @scaleflex/icons@1.0.0-beta.99

npm WARN Found: react@18.2.0

npm WARN node_modules/react

npm WARN   react@"18.2.0" from filerobot-image-editor@4.5.1

npm WARN   node_modules/filerobot-image-editor

npm WARN     filerobot-image-editor@"^4.5.1" from the root project

npm WARN   12 more (react-konva, styled-components, its-fine, ...)

npm WARN 

npm WARN Could not resolve dependency:

npm WARN peer react@"^16.13.1" from @scaleflex/icons@1.0.0-beta.99

npm WARN node_modules/@scaleflex/icons

npm WARN   @scaleflex/icons@"^1.0.0-beta.99" from @scaleflex/ui@1.0.0-beta.99

npm WARN   node_modules/@scaleflex/ui

npm WARN   1 more (react-filerobot-image-editor)

npm WARN 

npm WARN Conflicting peer dependency: react@16.14.0

npm WARN node_modules/react

npm WARN   peer react@"^16.13.1" from @scaleflex/icons@1.0.0-beta.99

npm WARN   node_modules/@scaleflex/icons

npm WARN     @scaleflex/icons@"^1.0.0-beta.99" from @scaleflex/ui@1.0.0-beta.99

npm WARN     node_modules/@scaleflex/ui

npm WARN     1 more (react-filerobot-image-editor)

npm WARN ERESOLVE overriding peer dependency

npm WARN While resolving: @scaleflex/icons@1.0.0-beta.99

npm WARN Found: react-dom@18.2.0

npm WARN node_modules/react-dom

npm WARN   react-dom@"18.2.0" from filerobot-image-editor@4.5.1

npm WARN   node_modules/filerobot-image-editor

npm WARN     filerobot-image-editor@"^4.5.1" from the root project

npm WARN   5 more (react-konva, styled-components, ...)

npm WARN 

npm WARN Could not resolve dependency:

npm WARN peer react-dom@"^16.13.1" from @scaleflex/icons@1.0.0-beta.99

npm WARN node_modules/@scaleflex/icons

npm WARN   @scaleflex/icons@"^1.0.0-beta.99" from @scaleflex/ui@1.0.0-beta.99

npm WARN   node_modules/@scaleflex/ui

npm WARN   1 more (react-filerobot-image-editor)

npm WARN 

npm WARN Conflicting peer dependency: react-dom@16.14.0

npm WARN node_modules/react-dom

npm WARN   peer react-dom@"^16.13.1" from @scaleflex/icons@1.0.0-beta.99

npm WARN   node_modules/@scaleflex/icons

npm WARN     @scaleflex/icons@"^1.0.0-beta.99" from @scaleflex/ui@1.0.0-beta.99

npm WARN     node_modules/@scaleflex/ui

npm WARN     1 more (react-filerobot-image-editor)

npm WARN ERESOLVE overriding peer dependency

npm WARN While resolving: @scaleflex/ui@1.0.0-beta.99

npm WARN Found: react@18.2.0

npm WARN node_modules/react

npm WARN   react@"18.2.0" from filerobot-image-editor@4.5.1

npm WARN   node_modules/filerobot-image-editor

npm WARN     filerobot-image-editor@"^4.5.1" from the root project

npm WARN   12 more (react-konva, styled-components, its-fine, ...)

npm WARN 

npm WARN Could not resolve dependency:

npm WARN peer react@"^16.13.1" from @scaleflex/ui@1.0.0-beta.99

npm WARN node_modules/@scaleflex/ui

npm WARN   @scaleflex/ui@"1.0.0-beta.99" from react-filerobot-image-editor@4.5.1

npm WARN   node_modules/react-filerobot-image-editor

npm WARN 

npm WARN Conflicting peer dependency: react@16.14.0

npm WARN node_modules/react

npm WARN   peer react@"^16.13.1" from @scaleflex/ui@1.0.0-beta.99

npm WARN   node_modules/@scaleflex/ui

npm WARN     @scaleflex/ui@"1.0.0-beta.99" from react-filerobot-image-editor@4.5.1

npm WARN     node_modules/react-filerobot-image-editor

npm WARN ERESOLVE overriding peer dependency

npm WARN While resolving: @scaleflex/ui@1.0.0-beta.99

npm WARN Found: react-dom@18.2.0

npm WARN node_modules/react-dom

npm WARN   react-dom@"18.2.0" from filerobot-image-editor@4.5.1

npm WARN   node_modules/filerobot-image-editor

npm WARN     filerobot-image-editor@"^4.5.1" from the root project

npm WARN   5 more (react-konva, styled-components, ...)

npm WARN 

npm WARN Could not resolve dependency:

npm WARN peer react-dom@"^16.13.1" from @scaleflex/ui@1.0.0-beta.99

npm WARN node_modules/@scaleflex/ui

npm WARN   @scaleflex/ui@"1.0.0-beta.99" from react-filerobot-image-editor@4.5.1

npm WARN   node_modules/react-filerobot-image-editor

npm WARN 

npm WARN Conflicting peer dependency: react-dom@16.14.0

npm WARN node_modules/react-dom

npm WARN   peer react-dom@"^16.13.1" from @scaleflex/ui@1.0.0-beta.99

npm WARN   node_modules/@scaleflex/ui

npm WARN     @scaleflex/ui@"1.0.0-beta.99" from react-filerobot-image-editor@4.5.1

npm WARN     node_modules/react-filerobot-image-editor



> flydiz@1.0.0 postinstall

> nuxt prepare



[warn] Using experimental payload extraction for full-static output. You can opt-out by setting `experimental.payloadExtraction` to `false`.

[success] Types generated in .nuxt

@danielroe I Guess this is only happening when preset is static ,

Checked on Windows / MaC .

image

  • [ ]

Update : Found out it was unable to build '@vuestic/nuxt', removing it from nuxt.config.ts made the terminal to conttinue to start server, but the issue is not fixed,

it was working well in nuxt 3.5.2 release.

I have the same problem but I'm not using @vuestic/nuxt. It's stuck on:

postinstall

nuxt prepare

[success] Types generated in .nuxt

This is caused by vuestic/nuxt registering a watcher, without signalling it to close. I've opened epicmaxco/vuestic-ui#3748 to fix that.

@pi0, I think we should probably still exit nuxi even if watchers are still around - can you think what might be causing this?

@danielroe I also have the same problem but I'm not using vuestic. Some core libs like nuxt/content, nuxt/image-edge, fontaine etc. The only third party package is 'nuxt-content-assets'. Please let me know if you want me to create a separate issue for that.

same problem with static used for some pages

Had the same issue; removing the 'nuxt-content-assets' module resolved it.

Same issue and I am not using vuestic/nuxt or nuxt-content-assets

(edit) I realized that removing the module nuxt-mongoose resolves this issue but I don't know if is a problem of the module or how I implement it.

Happens for me too when prerendering any route (even /sitemap.xml) when the app uses @nuxt/image. Other apps that dont use @nuxt/image can prerender fine.

It looks like this problems can be caused by many libraries like vuestic, nuxt-content-assets and @nuxt/image. I'm prerendering sitemap in my project so it may be connected.

Also in nuxt-vitest latest update (owing to cli update). Was resolved when downgrading cli to 3.7.3.

see danielroe/nuxt-vitest#324

pi0 commented

I am not sure if the main issue of nuxt prepare is the same as other reports here in this issue and would really appreciate if anyone else facing similar hanging problem, use a new issue with a working reproduction.


For last issue with nuxt-vitest and dev command, passing nuxt dev --no-fork fixed the issue.

Nuxt Content Assets author here.

Happy to help if possible, but Nuxt development moves so quickly, I'm not sure I can.

@pi0 - any advice on where to look in my module?

For the time being, I'll upgrade to Nuxt 2.8 in the module demo folder, and will create a new issue with the demo folder being the reproduction if it happens there.

pi0 commented

A note from nuxt/nuxt#23334, nitro pre-renderer does not calls close hook it seems to allow authors properly close instances (need to investigate more).

using workaround given by @pi0 here :
nuxt/nuxt#23334 (comment)

This workaround has nasty side effect:
1- nuxt prepare doesn't generate ts.config files in ./.nuxt folder
2- nuxt-vitest stop working properly

L422Y commented

Occurring for me when running bun run build and pre-rendering anything using any of the methods, i.e. an array of routes in nitro.prerender.routes or using just nitro.static: true ... bun run generate and bun run build --prerender both also hang.

If I remove that configuration, I can use bun run build successfully

L422Y commented

Using ps-tree thinking maybe I've a rogue child process, I'm seeing two esbuild child processes (and the ps command from ps-tree):

โœ” You can preview this build using npx serve .output/public                                                                                                                                                                         nitro 12:21:35 AM
Child processes: [ { parent_process_id: '59355',                                                                                                                                                                                           12:21:35 AM
    process_id: '59363',
    command:
     '@/node_modules/.pnpm/registry.npmjs.org+@esbuild+darwin-arm64@0.19.5/node_modules/@esbuild/darwin-arm64/bin/esbuild' },
  { parent_process_id: '59355',
    process_id: '59365',
    command:
     '@/node_modules/.pnpm/registry.npmjs.org+@esbuild+darwin-arm64@0.18.20/node_modules/@esbuild/darwin-arm64/bin/esbuild' },
  { parent_process_id: '59355', process_id: '59434', command: 'ps' } ]

This is what I added to the close hook, maybe it will help someone else:

import pstree from "ps-tree"

export default defineNuxtConfig({
 hooks: {
        "close": () => {
                pstree(process.pid, (err, children) => {
                if (err) {
                    console.error(err)
                    return
                }
                console.log("Child processes:", children.map(p => (
                        {
                            parent_process_id: p.PPID,
                            process_id: p.PID,
                            command: p.COMM.replace(__dirname, "@")
                        }
                    )
                ))
            })
        }
    },
  })

Would it make sense add something like this to the Nuxt codebase itself?

L422Y commented

This seems like it might possibly be relevant:
evanw/esbuild#985 (comment)

This is almost certainly because of this:
evanw/esbuild#2727 (comment)

As, with the pstree command (brew install pstree) we see the --ping argument:

\-+= 09637 larry ~/Applications/WebStorm.app/Contents/MacOS/webstorm
   \-+= 00289 larry /bin/zsh --login -i
     \-+= 69336 larry bun run build
       \-+- 69337 larry node <redacted>/l422y/app/node_modules/.bin/../nuxt/bin/nuxt.mjs build
         |--- 69348 larry <redacted>/l422y/app/node_modules/.pnpm/registry.npmjs.org+@esbuild+darwin-arm64@0.19.5/node_modules/@esbuild/darwin-arm64/bin/esbuild --service=0.19.5 --ping
         |--- 69349 larry <redacted>/l422y/app/node_modules/.pnpm/registry.npmjs.org+@esbuild+darwin-arm64@0.18.20/node_modules/@esbuild/darwin-arm64/bin/esbuild --service=0.18.20 --ping
         \-+- 69392 larry pstree -p 69337
           \--- 69393 root ps -axwwo user,pid,ppid,pgid,command

hm... even if i have node kill these, the process is not closing. which seems to suggest it's something internal like a promise that is not resolving..

When prerendering and using node-cron, build hangs

import cron from 'node-cron'

export default defineNitroPlugin(async () => {
  startCron()
})

function startCron() {
  cron.schedule('0 4 * * *', async () => {
    console.warn('Running scheduled task')
  })
  console.warn('Cron started'

Is there a way to detect if the environment is running for pre-rendering? That way we can skip things like cron when pre-rendering and avoid problems like that.

pi0 commented

@unitythemaker You can use process.static or import.meta.prerender static flags.

@unitythemaker You can use process.static or import.meta.prerender static flags.

Neither of those work out of the box within the nuxt close hook. process.static has a type error (easily ignoreable) and the other cant be used outside of a module.

any progress on this? my npm run build hangs on this line
โœ” You can preview this build using node .output/server/index.mjs nitro

im not using any of these 3 libraries vuestic, nuxt-content-assets and @nuxt/image

L422Y commented

check if any module or plugin you're using has a setTimeout in it, i had one that was, i was able to remove it from the library and it didn't hang anymore

We got the same issue and wasn't able to find the module or plugin that made our build process hang. It started happening after updating Nuxt and packages. Only esbuild was still running. We tried killing esbuild on close hook, but no luck.

It's hacky, but we ended up just exiting the process on close-hook. Nut sure if this is bad or not, but it made our application build again with no apparent issues. ๐Ÿ˜ธ

 hooks: {
    close: (nuxt) => {
      if (!nuxt.options._prepare) {
        process.exit();
      }
    },
  },

I'm running nuxi build on a Nuxt-Brigde project.

Also hanging on:
โœ” You can preview this build using node .output/server/index.mjs

nuxt prepare just started hanging for me and I'm not sure why. I think it might be due to execSync commands in the 'build:before' hook but this wasn't causing an issue before. ๐Ÿค”

I got this to work by doing the opposite of what @ngajhede did:

    close: (nuxt) => {
      if (nuxt.options._prepare) {
        process.exit()
      }
    }
L422Y commented

I feel like it might be useful to have some sort of "registry" of promises or long running timers so we could alert the user and even cleanly close them/time them out ofter generating. How bad would it be to extend/override/wrap the Promise class and timers to do this sort of thing?

I know this could have an effect on garbage collection, but the benefits might outweigh the negatives, and even enhance troubleshooting or debugging memory issues.

UPDATE:

Looks like my build was also hanging after it was complete like reported by other people, so I just changed the hook to:

    /** @see https://github.com/nuxt/cli/issues/169 */
    close: () => {
      process.exit()
    }

Update of update:

This doesn't work. It fails to build tsconfig.json, so I'm not sure what to do. If I remove the close hook, it builds tsconfig.json, but then never ends the build / prepare

L422Y commented

Try and isolate the root cause, it seems to differ from project to project, I would probably clone a minimal version of your project with plugins and dependencies, then step through one by one disabling each to see if it still hangs.

@L422Y Thank you!! It was my own derpy fault for not understanding how Nuxt modules work or when they run. I added a chokidar.watch in a custom Nuxt module to re-compile SCSS files on changes, since in my case, they need to be pre-compiled as themes and swapped at runtime. I intended it just for dev mode, and didn't realize the modules would run for something like nuxt prepare or nuxt build. I was able to fix it.

I had this problem in Nuxt-Bridge with vite:false. Now that I am upgrading to 3 with vite:true, it doesnt hang anymore.

Just upgraded a project to the latest Nuxt 10.3 , and it builds locally but stalls on Netlify.

CleanShot 2024-02-16 at 15 23 19

However, adding the fix mentioned above allows Netlify to proceed to the build step, with seemingly no adverse effects:

// nuxt.config.ts
  hooks: {
    close: () => {
      // @see https://github.com/nuxt/cli/issues/169#issuecomment-1729300497
      // Workaround for https://github.com/nuxt/cli/issues/169
      process.exit(0)
    }
  },

As I understand from the other comments:

  • the stall is likely triggered (but not caused) by Nuxt Content Assets (I'm the author of this module)
  • however, it should be solved in the project's config

@pi0 / @danielroe โ€“ what would be the best way for Nuxt Content Assets to mitigate this problem for its users?

  • It seems that it's needed for some folks / environments but not others.
  • Is this something I can / should solve in the module, and should it be in code, or perhaps documentation?

I don't understand the underlying mechanisms / reasons well enough to make that decision, so if you could make a recommendation I would appreciate it.

Thanks.

I am facing this issue after installing the nuxt/content@2.12.1 Module.

Nuxt build does not end even if all the buildings process completed

Nuxt Version: 3.11.2
CLI: 3.11.1
Nitro Version: 2.9.6
Node: 20.12.2

That would be a bug in the content module then. Would you open an issue on nuxt/content with a reproduction? Feel free to tag me.

For anyone still encountering this, a reminder that this typically occurs because of non-Nuxt code, typically within modules, but it can be anything that leaves something un-cleaned-up, such as a watcher.

I looked into the repo in #193 and also found an issue with Nitro, which was likely also at play: unjs/nitro#2287

If you're still encountering something like this in your project after that point, please open a new issue with a reproduction and I'll happily look into it further ๐Ÿ™