Skip to content

[BUG] Terminating process throws TypeError #11

@billyjanitsch

Description

@billyjanitsch

What / Why

#9 introduced an issue whereby an error is thrown when an npm script process is terminated.

When

Consistently, following the repro below.

Where

Any project. macOS 10.15.7, Node 14.14.0, npm 7.0.6.

How

  • n/a

Current Behavior

This line assumes that the callback will always be invoked with an object:

proc.once('exit', ({ code }) => {

However, this is evidently not the case:

21 verbose stack TypeError: Cannot destructure property 'code' of 'object null' as it is null.
21 verbose stack     at ChildProcess.<anonymous> (/Users/billy/.config/nvm/14.14.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/signal-manager.js:36:24)
21 verbose stack     at Object.onceWrapper (events.js:422:26)
21 verbose stack     at ChildProcess.emit (events.js:315:20)
21 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)

Steps to Reproduce

  1. Create a package.json with a script foo that includes a long-running process.
  2. Run npm run foo.
  3. Terminate the script early, e.g., by pressing ctrl+c.

Expected Behavior

The process should terminate without throwing an error, or at least by throwing a more intelligible error.

Who

@nlf, @isaacs

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions