Skip to content
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

nuxi prepare or build hangs #169

Closed
mrniamster opened this issue Aug 26, 2023 · 38 comments
Closed

nuxi prepare or build hangs #169

mrniamster opened this issue Aug 26, 2023 · 38 comments
Labels

Comments

@mrniamster
Copy link

mrniamster commented Aug 26, 2023

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
@stackblitz
Copy link

stackblitz bot commented Aug 26, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@mrniamster
Copy link
Author

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

Checked on Windows / MaC .

image

  • [ ]

@mrniamster
Copy link
Author

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.

@michalkuncio
Copy link

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

postinstall

nuxt prepare

[success] Types generated in .nuxt

@danielroe
Copy link
Member

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?

@michalkuncio
Copy link

@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.

@AndrewBogdanovTSS
Copy link

same problem with static used for some pages

@jennie
Copy link

jennie commented Aug 28, 2023

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

@negativems
Copy link

negativems commented Sep 2, 2023

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.

@danielroe danielroe changed the title Nuxt 3.7 - Not coming out of terminal – stuck in npm install nuxt prepare step hangs Sep 6, 2023
@erikknorren
Copy link

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.

@michalkuncio
Copy link

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.

@danielroe danielroe transferred this issue from nuxt/nuxt Sep 11, 2023
@danielroe
Copy link
Member

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
Copy link
Member

pi0 commented Sep 12, 2023

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.

@davestewart
Copy link

davestewart commented Sep 14, 2023

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
Copy link
Member

pi0 commented Sep 21, 2023

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).

@CharlesBT
Copy link

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
Copy link
Contributor

L422Y commented Nov 4, 2023

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
Copy link
Contributor

L422Y commented Nov 5, 2023

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
Copy link
Contributor

L422Y commented Nov 5, 2023

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..

@productdevbook
Copy link
Member

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'

@unitythemaker
Copy link

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
Copy link
Member

pi0 commented Nov 10, 2023

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

@philipimperato
Copy link

@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.

@djixadin
Copy link

djixadin commented Jan 11, 2024

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
Copy link
Contributor

L422Y commented Jan 11, 2024

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

@ngajhede
Copy link

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();
      }
    },
  },

@HendrikJan
Copy link

HendrikJan commented Jan 19, 2024

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

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

@matthew-dean
Copy link

matthew-dean commented Feb 7, 2024

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
Copy link
Contributor

L422Y commented Feb 7, 2024

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.

@matthew-dean
Copy link

matthew-dean commented Feb 7, 2024

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
Copy link
Contributor

L422Y commented Feb 15, 2024

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.

@matthew-dean
Copy link

matthew-dean commented Feb 15, 2024

@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.

@HendrikJan
Copy link

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

@davestewart
Copy link

davestewart commented Feb 16, 2024

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.

vitormarcal added a commit to vitormarcal/marcal-blog that referenced this issue Mar 2, 2024
@rashidpathiyil
Copy link

rashidpathiyil commented May 19, 2024

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

@danielroe
Copy link
Member

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.

@danielroe
Copy link
Member

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: nitrojs/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 🙏

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale May 19, 2024
@acuteaura
Copy link

I'm seeing this when turning on typescript.typeCheck. I'm very confused, that shouldn't cause any extra code to run?

Also only happens building in a docker container (matching bun version). Even if I delete .nuxt, .output and node_modules and repeat the steps from the container, it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests