Skip to content

Errors in postinstall scripts are ignored #21662

Closed

Description

@willemv

Description of the bug

When the postinstall script of the project itself fails, the frontend build as well as the devserver tasks silently ignore this failure.

Expected behavior

The production build task as well as the devserver should fail to proceed, and show the error output produced by the postinstall task.

Minimal reproducible example

Configure a postinstall script that fails, for instance:

{
  "scripts": {
    "postinstall": "node -e 'console.error(\"failure\"); process.exit(5)'"
  },
  "...": "..."
}

Example with patch-package

In our specific situation, we use the patch-package npm module to work around issues in 3rd party libraries that are not yet (or never will be) accepted upstream.

We use this in postinstall script in our package.json file, as documented for the patch-package module, like so:

{
  "...": "...",
  "scripts": {
    "postinstall": "patch-package --error-on-fail"
  },
  "....": "..."
}

This postinstall script will fail with a non-zero exitcode if the patches we maintain don't cleanly apply anymore. This is a good thing, because then we should investigate how the 3rd-party library changed and whether we have to update or get rid of our patch.

But because the frontend build functionality in the gradle plugin, as well as the dev-server that hot-reloads the frontend bundle, silently ignore this error, we weren't notified of these errors at all.

Code pointer

The problem is caused by TaskRunNpmInstall.java#L396 ignoring the exit code of process.waitFor

That code should inspect the exit code, and if it is non-zero throw an exception. In that case, the output of the process should also be shown on the console. Right now, the output of the process is only logged on the debug level.

Versions

  • Vaadin / Flow version: 24.7.5
  • Java version: 21
  • OS version: any
  • Browser version (if applicable): N/A
  • Application Server (if applicable): N/A
  • IDE (if applicable): N/A

Activity

  1. added theissue type on Jun 17, 2025
  2. moved this to 🔖 Normal Priority (P2) in Vaadin Flow bugs & maintenanceon Jun 17, 2025
  3. moved this from 🔖 Normal Priority (P2) to ✅ Closed in Vaadin Flow bugs & maintenanceon Sep 17, 2026
  4. totally-not-ai commented on Sep 17, 2026

    @totally-not-ai
    Contributor

    Analysis

    This is a real bug, and the code pointer in the report is accurate.

    Root cause

    TaskRunNpmInstall runs the install with --ignore-scripts and then runs the postinstall script of each package in the postinstall list explicitly (the list starts with ".", i.e. the project's own package.json, which is the patch-package case here). That explicit run captured the process output into a debug-level log and then called process.waitFor() without looking at the exit code, so a failing script left no trace above debug level and the build/dev server continued with a half-patched node_modules.

    There was a second, pnpm-only problem in the same place: pnpm run postinstall first performs its verify-deps-before-run check, which kicks off an install of its own. That install repeats the one Flow just ran but without --ignore-scripts and without the arguments that exempt Vaadin's own packages from the minimum release age, so on pnpm it frequently failed — and when it did, the postinstall script was never executed at all (that was tracked as #24333).

    Status

    Both are fixed on main by #25779, which is why this issue got closed automatically. The behaviour now:

    • A postinstall script that exits non-zero fails the task with an ExecutionFailedException that names the package and includes the script's captured stdout/stderr, instead of the exit code being discarded.
    • The postinstall command gets --config.verify-deps-before-run=false when pnpm is the package manager (nothing extra for npm, and nothing for bun, which rejects unknown arguments).
    • This covers both entry points mentioned in the report: the production frontend build (prepare-frontend/build-frontend in the Maven and Gradle plugins) fails the build, and in development the node tasks failure propagates out of DevModeInitializer.runNodeTasks, so the dev server reports the error instead of hot-reloading a broken bundle.

    Regression coverage was added in TaskRunNpmInstallTest (a fake package whose postinstall prints to stderr and exits non-zero must make execute() throw with the package name and the script output), plus unit tests for the resolved postinstall arguments per package manager.

    Note on the behaviour change

    Projects that until now had a silently failing postinstall script will start failing their build. That is the intended fix, but if someone needs to opt a package out, excludePostinstallPackages (Maven: vaadin.npm.excludePostinstallPackages, Gradle: excludePostinstallPackages) accepts . for the project's own package.json.

    Backporting

    The fix is labelled for 25.2 and 25.3. @willemv — since you reported this against 24.7.5, please say if you need it on the 24.x line as well, so a maintainer can decide on an additional cherry-pick.

  5. added a commit that references this issue on Sep 17, 2026
    4e0f994
  6. added a commit that references this issue on Sep 18, 2026
    584fcb8
  7. willemv commented on Sep 22, 2026

    @willemv
    ContributorAuthor

    I don't need a backport to 24.x, thanks.

  8. added a commit that references this issue on Sep 29, 2026
    cbc725d
  9. vaadin-bot commented on Sep 29, 2026

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 25.4.0-alpha1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions