cli icon indicating copy to clipboard operation
cli copied to clipboard

nuxi `prepare` or `build` hangs

Open mrniamster opened this issue 2 years ago • 34 comments

Environment



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/[email protected]

npm WARN Found: [email protected]

npm WARN node_modules/react

npm WARN   react@"18.2.0" from [email protected]

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/[email protected]

npm WARN node_modules/@scaleflex/icons

npm WARN   @scaleflex/icons@"^1.0.0-beta.99" from @scaleflex/[email protected]

npm WARN   node_modules/@scaleflex/ui

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

npm WARN 

npm WARN Conflicting peer dependency: [email protected]

npm WARN node_modules/react

npm WARN   peer react@"^16.13.1" from @scaleflex/[email protected]

npm WARN   node_modules/@scaleflex/icons

npm WARN     @scaleflex/icons@"^1.0.0-beta.99" from @scaleflex/[email protected]

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/[email protected]

npm WARN Found: [email protected]

npm WARN node_modules/react-dom

npm WARN   react-dom@"18.2.0" from [email protected]

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/[email protected]

npm WARN node_modules/@scaleflex/icons

npm WARN   @scaleflex/icons@"^1.0.0-beta.99" from @scaleflex/[email protected]

npm WARN   node_modules/@scaleflex/ui

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

npm WARN 

npm WARN Conflicting peer dependency: [email protected]

npm WARN node_modules/react-dom

npm WARN   peer react-dom@"^16.13.1" from @scaleflex/[email protected]

npm WARN   node_modules/@scaleflex/icons

npm WARN     @scaleflex/icons@"^1.0.0-beta.99" from @scaleflex/[email protected]

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/[email protected]

npm WARN Found: [email protected]

npm WARN node_modules/react

npm WARN   react@"18.2.0" from [email protected]

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/[email protected]

npm WARN node_modules/@scaleflex/ui

npm WARN   @scaleflex/ui@"1.0.0-beta.99" from [email protected]

npm WARN   node_modules/react-filerobot-image-editor

npm WARN 

npm WARN Conflicting peer dependency: [email protected]

npm WARN node_modules/react

npm WARN   peer react@"^16.13.1" from @scaleflex/[email protected]

npm WARN   node_modules/@scaleflex/ui

npm WARN     @scaleflex/ui@"1.0.0-beta.99" from [email protected]

npm WARN     node_modules/react-filerobot-image-editor

npm WARN ERESOLVE overriding peer dependency

npm WARN While resolving: @scaleflex/[email protected]

npm WARN Found: [email protected]

npm WARN node_modules/react-dom

npm WARN   react-dom@"18.2.0" from [email protected]

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/[email protected]

npm WARN node_modules/@scaleflex/ui

npm WARN   @scaleflex/ui@"1.0.0-beta.99" from [email protected]

npm WARN   node_modules/react-filerobot-image-editor

npm WARN 

npm WARN Conflicting peer dependency: [email protected]

npm WARN node_modules/react-dom

npm WARN   peer react-dom@"^16.13.1" from @scaleflex/[email protected]

npm WARN   node_modules/@scaleflex/ui

npm WARN     @scaleflex/ui@"1.0.0-beta.99" from [email protected]

npm WARN     node_modules/react-filerobot-image-editor



> [email protected] 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

mrniamster avatar Aug 26 '23 18:08 mrniamster

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

Checked on Windows / MaC .

image

  • [ ]

mrniamster avatar Aug 26 '23 19:08 mrniamster

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.

mrniamster avatar Aug 27 '23 03:08 mrniamster

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

postinstall

nuxt prepare

[success] Types generated in .nuxt

michalkuncio avatar Aug 27 '23 12:08 michalkuncio

This is caused by vuestic/nuxt registering a watcher, without signalling it to close. I've opened https://github.com/epicmaxco/vuestic-ui/pull/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 avatar Aug 27 '23 22:08 danielroe

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

michalkuncio avatar Aug 28 '23 00:08 michalkuncio

same problem with static used for some pages

AndrewBogdanovTSS avatar Aug 28 '23 15:08 AndrewBogdanovTSS

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

jennie avatar Aug 28 '23 18:08 jennie

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.

negativems avatar Sep 02 '23 19:09 negativems

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.

erikknorren avatar Sep 07 '23 09:09 erikknorren

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.

michalkuncio avatar Sep 07 '23 10:09 michalkuncio

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

see https://github.com/danielroe/nuxt-vitest/pull/324

danielroe avatar Sep 12 '23 18:09 danielroe

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.

  • https://github.com/danielroe/nuxt-vitest/pull/335
  • https://github.com/nuxt/cli/pull/174

pi0 avatar Sep 12 '23 21:09 pi0

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.

davestewart avatar Sep 14 '23 11:09 davestewart

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

pi0 avatar Sep 21 '23 10:09 pi0

using workaround given by @pi0 here : https://github.com/nuxt/nuxt/issues/23334#issuecomment-1752170942

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

CharlesBT avatar Oct 08 '23 21:10 CharlesBT

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 avatar Nov 04 '23 14:11 L422Y

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+@[email protected]/node_modules/@esbuild/darwin-arm64/bin/esbuild' },
  { parent_process_id: '59355',
    process_id: '59365',
    command:
     '@/node_modules/.pnpm/registry.npmjs.org+@[email protected]/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 avatar Nov 05 '23 04:11 L422Y

This seems like it might possibly be relevant: https://github.com/evanw/esbuild/issues/985#issuecomment-1718768339

This is almost certainly because of this: https://github.com/evanw/esbuild/issues/2727#issuecomment-1343153719

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+@[email protected]/node_modules/@esbuild/darwin-arm64/bin/esbuild --service=0.19.5 --ping
         |--- 69349 larry <redacted>/l422y/app/node_modules/.pnpm/registry.npmjs.org+@[email protected]/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..

L422Y avatar Nov 05 '23 04:11 L422Y

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'

productdevbook avatar Nov 10 '23 09:11 productdevbook

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.

unitythemaker avatar Nov 10 '23 13:11 unitythemaker

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

pi0 avatar Nov 10 '23 14:11 pi0

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

philipimperato avatar Nov 30 '23 18:11 philipimperato

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

djixadin avatar Jan 11 '24 10:01 djixadin

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

L422Y avatar Jan 11 '24 10:01 L422Y

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

ngajhede avatar Jan 17 '24 16:01 ngajhede

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

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

HendrikJan avatar Jan 19 '24 11:01 HendrikJan

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

matthew-dean avatar Feb 07 '24 16:02 matthew-dean

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.

L422Y avatar Feb 07 '24 16:02 L422Y

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

matthew-dean avatar Feb 07 '24 16:02 matthew-dean