Skip to content

Errors in postinstall scripts are ignored #21662

Open
@willemv

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    🔖 Normal Priority (P2)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions