Node modules cause error

When I run a server-side plugin that uses node modules in a workflow, I get the error message “Sorry, we have encountered an unexpected error.”

Here is my code and package.json.

function(properties, context) {
    var parser = require('ua-parser-js');
    console.log("test");
}

{
    "dependencies": {
        "ua-parser-js": "0.7.21"
    }
}

This phenomenon occurs not only when using ua-parse-js but also when using other packages.
What’s going on?