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

rollup -c not quit after created bundle #4213

Closed
sunshineplan opened this issue Aug 28, 2021 · 31 comments · Fixed by #4969 or #5195
Closed

rollup -c not quit after created bundle #4213

sunshineplan opened this issue Aug 28, 2021 · 31 comments · Fixed by #4969 or #5195

Comments

@sunshineplan
Copy link

Rollup Version

2.56.3

Operating System (or Browser)

windows-latest, ubuntu-latest, macos-latest in github actions

Node Version (if applicable)

16.8.0

Link To Reproduction

https://github.com/sunshineplan/sda/actions/runs/1174174007

Expected Behaviour

rollup quit after created bundle, so other github actions will go on.

Actual Behaviour

rollup hang up after created bundle

@phuocng
Copy link

phuocng commented Aug 28, 2021

I faced the same issue: rollup 2.56.3 on macOS 11.5.2, NodeJS 14.17.5

@theplayer06
Copy link

I have same issue in wsl2 - window 10

@laurentpayot
Copy link

Same issue on Ubuntu 21.04 with node 15.11.0

@vvinogradsky
Copy link

Same here on Windows 10

@nicholas-ochoa
Copy link

Same issue here. I noticed it seemed to be (at least in my case) related to the version of TypeScript. When I upgraded to 4.4.2 (latest as of right now). I downgraded to TypeScript 4.3.5 and it seemed to resolve my problem.

Occurring on Windows 10, WSL (Debian) and Linux (RHEL 8.4) - all using Node 14.17.5

@revelt
Copy link

revelt commented Aug 29, 2021

It seems the problem is with cli.js — it never exits (but only on certain environments, not everywhere):

This run(command) here

run(command);

Gets transpiled into runRollup(command):

...
else {
    try {
        require('source-map-support').install();
    }
    catch (err) {
        // do nothing
    }
    runRollup(command);
}

The runRollup() above is an async function and it needs to be manually exited!

If this error happens on your local machine, you can try editing node_modules/.bin/rollup and appending the .then(() => process.exit()); like this:

runRollup(command).then(() => process.exit());

Try. It's more difficult to do on a CI of course but still possible.

My research so far

  • It's not the Node version, I tried all versions
  • Issue is not happening on rollup-starter-lib on my machine (M1 Mac) — so rollup -c process goes zombie only on certain setups, not everywhere
  • It's got something to do with monorepo in my case (wiping lerna-generated node_modules and cding into one of packages and npm i solves the problem, rollup builds fine — but it's monorepo, long-term I can't short-circuit packages like that!)
  • It's not ES modules ("type": "module") or exports or anything to do with CJS being one of build targets

@sunshineplan
Copy link
Author

Same issue here. I noticed it seemed to be (at least in my case) related to the version of TypeScript. When I upgraded to 4.4.2 (latest as of right now). I downgraded to TypeScript 4.3.5 and it seemed to resolve my problem.

Occurring on Windows 10, WSL (Debian) and Linux (RHEL 8.4) - all using Node 14.17.5

Actually, I met this problem because of upgrading TypeScript by dependabot. I noticed it has some break changes.
https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#breaking-changes

@phuocng
Copy link

phuocng commented Aug 30, 2021

Downgrading TypeScript from 4.4.2 to 4.3.5 fixes the issue for me.
Thanks @sunshineplan and @nicholas-ochoa

@lingxiao-Zhu
Copy link

use rollup-plugin-typescript2 instead of rollup-plugin-typescript2

@sunshineplan
Copy link
Author

sunshineplan commented Aug 30, 2021

Also see rollup/plugins#983
microsoft/TypeScript#45642 fixed this problem, new release will be ok.

endel added a commit to colyseus/colyseus.js that referenced this issue Aug 31, 2021
rcasto added a commit to rcasto/edits that referenced this issue Sep 1, 2021
endel added a commit to colyseus/colyseus that referenced this issue Sep 1, 2021
joethei added a commit to joethei/obsidian-plantuml that referenced this issue Sep 3, 2021
nicoleoliveira added a commit to animaliads/animalia-web-components that referenced this issue Sep 3, 2021
Tem uma issue no typescript porque está travando o build.
microsoft/TypeScript#45642
rollup/rollup#4213
layday added a commit to layday/instawow that referenced this issue Sep 6, 2021
enisdenjo added a commit to enisdenjo/graphql-ws that referenced this issue Sep 8, 2021
enisdenjo added a commit to enisdenjo/graphql-ws that referenced this issue Sep 8, 2021
enisdenjo added a commit to enisdenjo/graphql-sse that referenced this issue Sep 8, 2021
exbotanical added a commit to exbotanical/vivisector that referenced this issue Sep 9, 2021
- tsc bug (peer dep req'd by rollup-plugin-dts) causes rollup builds to hang indefinitely; see: rollup/rollup#4213
nicoleoliveira added a commit to animaliads/animalia-web-components that referenced this issue Sep 10, 2021
* Novo componente 

* feat: correção da versão do typescript

Tem uma issue no typescript porque está travando o build.
microsoft/TypeScript#45642
rollup/rollup#4213
@sunshineplan
Copy link
Author

Fixed with TypeScript 4.4.3

@mattxyzeth
Copy link

I'm facing this problem. Typescript 4.6.3. @revelt is correct that this method needs to be awaited or completed with a then callback. How does Typescript affect this?

@revelt
Copy link

revelt commented Apr 4, 2022

@mattxyzeth if I may advise,

  1. rule out basics — ensure you actually have the latest ts and rollup — check versions inside node_modules (or npm ls)
  2. double-check rollup plugins, are any out of date — if possible try disabling one-by-one
  3. try manually tweaking rollup cli inside node_modules/bin, add exiting runRollup(command).then(() => process.exit());
  4. build the proof case — try to recreate the MVP case to prove it's happening — strip your project to just intact rollup config and replace sources with a trivial function, strip any branding or sensitive info — post on stackblitz and share the link — we might have to reopen this ticket.

is correct that this method needs to be awaited or completed with a then callback

At least back then, when we were facing the problem, correct, that's what worked — but I rolled back my dependency bumps and waited it out until 4.4.3 (and eventually migrated to esbuild).

How does Typescript affect this?

If you mean the bug, it could have been anything. Typescript is a whole ecosystem — AST's, mapping of what-in-TS gets transpiled to what-in-JS and so on. For example, zalgo could have been released in the transpiled output. I don't know.

Personally, since, I migrated from rollup to esbuild for bundling, I use rollup only for generating .d.ts. See for example here and here.

@mattxyzeth
Copy link

mattxyzeth commented Apr 4, 2022

I'm not entirely convinced it's related to TS. My app has two builds—one for the app and one for the service workers. The build always hangs in my local environment for the app and never for the workers. On my CI server, it only hangs once in a while for the app and never for the workers.

As for your suggestions, I've ruled out the first two. The most stable combination is if I downgrade TS to 4.4.3, but it fails intermittently. Everything always works with any version if I apply the patch in number 3. I'm wondering why this isn't used as the default. Is there a downside to adding this?

EDIT: I upgraded all my rollup plugins that were not in common between my service worker's config and my app config. I also upgraded TS to the latest version. The build started exiting properly in my local environment. So I tried to mimic the exact same environment on my CI server except for the OS but it's still failing there. Then after a few tries in my local environment, it started to hang again, without any changes.

@mattxyzeth
Copy link

We've tracked down our issue to an unrelated animation package imported into our bundle. So it seems that this issue extends beyond the plugins. We don't have a clear idea of why this package was causing the build to not exit. The build completes successfully but doesn't exit 100% of the runs. We saw an average of a 30% success rate across multiple computers and environments. Unfortunately, I don't think that the patch mentioned in this thread is the ultimate solution since the problem could indicate a much larger issue in the bundle and not directly related to the build process. Maybe there should be some timeout error that means something was left hanging that has caused the build not to exit correctly.

@krohrsb
Copy link

krohrsb commented Apr 28, 2023

We ran into this when leveraging rollup in a RushJS monorepo. Multiple builds happening at the same time. When building the monorepo we would get rollup not exiting after building a package, on various packages (nothing deterministic). This was very common and very reproducible.

I tested the proposed solution from #4213 (comment) and this has seemingly solved the problem. Likely exasperated by multiple processes/concurrency?

I've got a local PNPM patch to test it more long term at the moment.

@isc30
Copy link

isc30 commented Apr 28, 2023 via email

@krohrsb
Copy link

krohrsb commented Apr 29, 2023

Wow we have exactly the same issue with RushJs, can you share more details
about your fix/patch please? Thanks a lot!

I use pnpm and so used https://pnpm.io/cli/patch in order to persist the change suggested by the comment I linked to in my previous reply. It's not a long term fix. Perhaps roll-up will accept a contribution.

@lukastaegert
Copy link
Member

Sorry for completely missing this issue. While I cannot reproduce it, adding the proposed force exit should not pose any problems, I will put it into the next release.

@lukastaegert
Copy link
Member

Please check out #4969

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4969 as part of rollup@3.21.3. You can test it via npm install rollup.

@chordmemory
Copy link

chordmemory commented Jun 22, 2023

Can we reopen this @lukastaegert? It looks like the fix has been reverted.

@lukastaegert lukastaegert reopened this Jun 23, 2023
@chordmemory
Copy link

chordmemory commented Aug 1, 2023

@lukastaegert I've had success using the same workaround from the revert pr.

For anyone struggling with this, but needing to intake new rollup versions, try adding this as the last plugin in your plugin array in rollup.config.js :

{
    closeBundle() {
        if (!process.env.ROLLUP_WATCH) {
          setTimeout(() => process.exit(0));
        }
    },
    name: 'force-close'
}

@jhanssen
Copy link

jhanssen commented Aug 2, 2023

@chordmemory thanks, I've been banging my head against this for the last couple days and your suggestion works well in my project

@isc30
Copy link

isc30 commented Aug 2, 2023

@chordmemory this works wonders, maybe rollup should have that inside the codebase just in case a plugin keeps handles open after outputting

@lukastaegert
Copy link
Member

That is what I tried, but it breaks a lot of stuff for other workflows. The only good solution would be to figure out what exactly is keeping the process open, but we had no success so far as it does not happen very reliably.

@chordmemory
Copy link

@lukastaegert I have a pretty complicated config that can reliably reproduce (1/2 times) - I can't share it, but do you have any advice or ideas for how to debug the leak?

@lukastaegert
Copy link
Member

lukastaegert commented Aug 4, 2023

Not really. To my knowledge, there are mostly two things that can prevent a process from completing:

  • asynchronous tasks that are still running
  • some kind of global event listeners

Maybe using the Chrome debugger attached to the Node process might give a clue what might still be running or scheduled. I had no luck reproducing the issue in a situation where I had a debugger attached so far.

@tjenkinson
Copy link
Member

Have you tried https://github.com/mafintosh/why-is-node-running ?

@woutervanvliet
Copy link

@lukastaegert I've had success using the same workaround from the revert pr.

For anyone struggling with this, but needing to intake new rollup versions, try adding this as the last plugin in your plugin array in rollup.config.js :

{
    closeBundle() {
        if (!process.env.ROLLUP_WATCH) {
          setTimeout(() => process.exit(0));
        }
    },
    name: 'force-close'
}

Thanks! I've implemented a solution based on your suggestion, and I feel rather confident this will work. Had to slightly modify it though, as my rollup config exports an array of configurations; and I want them all to complete. For anybody in a similar situation; here's my solution:

let runningBundles = 0

/**
 * @param {string} name
 * @param {number} maxWaitTime Maximum number of seconds to wait for Rollup to exit before force-exiting
 * @returns {{closeBundle(): void, buildStart(): void, name: string}}
 */
export const rollupForceExit = (name, maxWaitTime = 60) => {
    return {
        /** @this {import('rollup').PluginContext} */
        buildStart() {
            if (this.meta.watchMode) {
                return
            }

            runningBundles++
            this.info(`${name}: Starting build, ${runningBundles} build(s) running`)
        },
        /** @this {import('rollup').PluginContext} */
        closeBundle() {
            if (this.meta.watchMode) {
                return
            }

            runningBundles--
            const timeout = setTimeout(() => {
                if (runningBundles === 0) {
                    this.info(
                        `${name}: Rollup is now done, but did not exit before ${maxWaitTime} seconds, force exiting...`
                    )
                    process.exit(0)
                } else {
                    this.info(
                        `${name}: Rollup is still working on another build process, waiting for ${runningBundles} running bundle(s) before force exit`
                    )
                }
            }, maxWaitTime * 1000)
            // Allow the NodeJS process to finish without waiting for the timeout, using it only as a fallback for
            // otherwise hanging Rollup processes
            timeout.unref()
        },
        name: 'force-close',
    }
}

This also tries to account for any other plugins that might want to do some amount of work in closeBundle

Copy link

github-actions bot commented Nov 3, 2023

This issue has been resolved via #5195 as part of rollup@4.3.0. You can test it via npm install rollup.

ihiroky added a commit to ihiroky/live-comment that referenced this issue Feb 11, 2024
ihiroky added a commit to ihiroky/live-comment that referenced this issue Feb 11, 2024
* fix: Use npx, not yarn

* fix: Update common, server

* fix: Update comment

* chore: Update dependencies

* fix: Modify tests for poll

* fix: Use styled components

* fix: Update extention

* fix: update settings

* chore: Add package-lock.json

* fix: Use npx instead of yarn

* fix: Use npm to execute script

* fix: call eslint and jest through npm script

* fix: Use npm scripts

* fix: Use node 18.16.0

nodejs/node#51048

* fix: Fix type check

* fix: Update rollup-typescript plugin

* fix: Update rollup

rollup/rollup#4213

* fix: Update entry point

* fix: Add workaround for hung up on windows-latest

* fix: Add windows hungup workaround
jeffersonRibeiro added a commit to mendix/widgets-tools that referenced this issue Mar 6, 2024
## What is the purpose of this PR?

Sometimes when running the pluggable widget tools script for release or
build a widget, the rollup doesn’t finish the process. That happens in
the editorConfig step.

## Relevant changes

To resolve that for now I have followed one suggestion from the rollup
repository PR to force close the process because we’re still using
rollup v3 in the pluggable widget tools.

That was fixed in v4, it was created one new parameter to pass to rollup
to force exit. If so, then this fix can be removed and starts to use the
new parameter mentioned above.

rollup/rollup#4213 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet