Integrating newrelic on angular universal application (nodejs)

There is more elegant solution to described problem. You can set webpack externals field like function:

(context, request, callback) => {
    var regex = new RegExp(`^newrelic$`);

    if (regex.test(request)) {
        return callback(null, `commonjs ${request}`);
    }
    callback();
 }

This will tell webpack to leave const newrelic = require('newrelic'); as is in bundled file. All you need is to place node_modules with newrelic near your running server. The second solution is to set libraryType property of outputto commonjs then the following externals syntax will work:

externals : {
    newrelic : {
        commonjs: 'newrelic'
    }
}