Search code examples
node.jswebpackappdynamics

AppDynamics (Node.js/Express) dependencies broken compiling with Webpack--can anyone confirm?


Has anyone experienced Webpack dependency compiling issues when using the AppDynamics library? And did you find a way to work around it? I believe this is an issue stemming from their library.

When trying to install the AppDynamics package for monitoring a Node.js/Express application, our Webpack build process is not able to import a handful of dependencies. Specifically, the errors output are:

WARNING in ./node_modules/appdynamics/lib/core/agent.js 445:8-28
require.main.require is not supported by webpack.
 @ ./node_modules/appdynamics/index.js 1:17-44
 @ ./server.ts

ERROR in ./node_modules/appdynamics-zmq/lib/index.js
Module not found: Error: Can't resolve '../zmq' in '.../my-app/node_modules/appdynamics-zmq/lib'
 @ ./node_modules/appdynamics-zmq/lib/index.js 24:10-27
 @ ./node_modules/appdynamics-zmq/index.js
 @ ./node_modules/appdynamics/lib/libproxy/proxy-transport.js
 @ ./node_modules/appdynamics/lib/libproxy/libproxy.js
 @ ./node_modules/appdynamics/lib/core/agent.js
 @ ./node_modules/appdynamics/index.js
 @ ./server.ts

ERROR in ./node_modules/appdynamics-libagent/index.js
Module not found: Error: Can't resolve './appd_libagent' in '.../my-app/node_modules/appdynamics-libagent'
 @ ./node_modules/appdynamics-libagent/index.js 36:9-35
 @ ./node_modules/appdynamics/lib/libagent/libagent-connector.js
 @ ./node_modules/appdynamics/lib/core/agent.js
 @ ./node_modules/appdynamics/index.js
 @ ./server.ts

ERROR in ./node_modules/appdynamics-native/index.js
Module not found: Error: Can't resolve './appdynamics' in '.../my-app/node_modules/appdynamics-native'
 @ ./node_modules/appdynamics-native/index.js 29:10-34
 @ ./node_modules/appdynamics/lib/core/agent.js
 @ ./node_modules/appdynamics/index.js
 @ ./server.ts

ERROR in ./node_modules/appdynamics-protobuf/index.js
Module not found: Error: Can't resolve './protobuf_for_node' in '.../my-app/node_modules/appdynamics-protobuf'
 @ ./node_modules/appdynamics-protobuf/index.js 29:10-40
 @ ./node_modules/appdynamics/lib/libproxy/proxy-transport.js
 @ ./node_modules/appdynamics/lib/libproxy/libproxy.js
 @ ./node_modules/appdynamics/lib/core/agent.js
 @ ./node_modules/appdynamics/index.js
 @ ./server.ts

ERROR in ./node_modules/log4js/lib/appenders/hipchat.js
Module not found: Error: Can't resolve 'hipchat-notifier' in '.../my-app/node_modules/log4js/lib/appenders'
 @ ./node_modules/log4js/lib/appenders/hipchat.js 3:14-41
 @ ./node_modules/log4js/lib/appenders sync ^\.\/.*$
 @ ./node_modules/log4js/lib/log4js.js
 @ ./node_modules/appdynamics/lib/core/logger.js
 @ ./node_modules/appdynamics/lib/core/agent.js
 @ ./node_modules/appdynamics/index.js
 @ ./server.ts

ERROR in ./node_modules/log4js/lib/appenders/loggly.js
Module not found: Error: Can't resolve 'loggly' in '.../node_modules/log4js/lib/appenders'
 @ ./node_modules/log4js/lib/appenders/loggly.js 3:11-28
 @ ./node_modules/log4js/lib/appenders sync ^\.\/.*$
 @ ./node_modules/log4js/lib/log4js.js
 @ ./node_modules/appdynamics/lib/core/logger.js
 @ ./node_modules/appdynamics/lib/core/agent.js
 @ ./node_modules/appdynamics/index.js
 @ ./server.ts

ERROR in ./node_modules/log4js/lib/appenders/mailgun.js
Module not found: Error: Can't resolve 'mailgun-js' in '.../my-app/node_modules/log4js/lib/appenders'
 @ ./node_modules/log4js/lib/appenders/mailgun.js 34:14-35
 @ ./node_modules/log4js/lib/appenders sync ^\.\/.*$
 @ ./node_modules/log4js/lib/log4js.js
 @ ./node_modules/appdynamics/lib/core/logger.js
 @ ./node_modules/appdynamics/lib/core/agent.js
 @ ./node_modules/appdynamics/index.js
 @ ./server.ts

ERROR in ./node_modules/log4js/lib/appenders/smtp.js
Module not found: Error: Can't resolve 'nodemailer' in '.../my-app/node_modules/log4js/lib/appenders'
 @ ./node_modules/log4js/lib/appenders/smtp.js 4:13-34
 @ ./node_modules/log4js/lib/appenders sync ^\.\/.*$
 @ ./node_modules/log4js/lib/log4js.js
 @ ./node_modules/appdynamics/lib/core/logger.js
 @ ./node_modules/appdynamics/lib/core/agent.js
 @ ./node_modules/appdynamics/index.js
 @ ./server.ts

ERROR in ./node_modules/log4js/lib/appenders/slack.js
Module not found: Error: Can't resolve 'slack-node' in '.../node_modules/log4js/lib/appenders'
 @ ./node_modules/log4js/lib/appenders/slack.js 2:12-33
 @ ./node_modules/log4js/lib/appenders sync ^\.\/.*$
 @ ./node_modules/log4js/lib/log4js.js
 @ ./node_modules/appdynamics/lib/core/logger.js
 @ ./node_modules/appdynamics/lib/core/agent.js
 @ ./node_modules/appdynamics/index.js
 @ ./server.ts

Our project is set up with: - Webpack v4.29.0 - Node.js v11.0.0 - Appdynamics v4.5

The Appdynamics usage is at the top of our server file as:

// AppDynamics monitoring
require("appdynamics").profile({
  controllerHostName: ***
  controllerPort: 443, 
  controllerSslEnabled: true,  
  accountName: ****
  accountAccessKey: ***
  applicationName: ***
  tierName: ***
  nodeName: '01'
 });

And our Webpack configuration is:

const path = require('path');
const webpack = require('webpack');

module.exports = {
  entry: { server: './server.ts' },
  resolve: { extensions: ['.js', '.ts'] },
  target: 'node',
  // TO-DO: Enable "production" mode for going live with Universal
  mode: 'development',
  // this makes sure we include node_modules and other 3rd party libraries
  externals: [/node_modules/],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
  },
  module: {
    rules: [{ test: /\.ts$/, loader: 'ts-loader' }]
  },
  plugins: [
  ]
};

So far we have tried downgrading the Webpack version, downgrading the Node environment to 10.15, and using other import methods for the AppDynamics package, but this seems like an issue internal to the Appdynamics library? The main question is, has anyone experienced Webpack dependency compiling issues when using the Appdynamics library? And did you find a way to work around it?

Any help or clues would be appreciated ❤️


Solution

  • The solution was adding "appdynamics" to the "externals" in the Webpack configuration: https://webpack.js.org/configuration/externals/

    This allows AppDynamics to use the default Node.js require import.