首页 > 解决方案 > AppDynamics (Node.js/Express) 依赖项破坏了使用 Webpack 进行编译——任何人都可以确认吗?

问题描述

有没有人在使用 AppDynamics 库时遇到过 Webpack 依赖编译问题?你找到解决方法了吗?我相信这是源于他们的图书馆的问题。

当尝试安装 AppDynamics 包以监控 Node.js/Express 应用程序时,我们的 Webpack 构建过程无法导入少量依赖项。具体来说,错误输出是:

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

我们的项目设置为: - Webpack v4.29.0 - Node.js v11.0.0 - Appdynamics v4.5

Appdynamics 用法位于我们服务器文件的顶部,如下所示:

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

而我们的 Webpack 配置是:

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: [
  ]
};

到目前为止,我们已经尝试降级 Webpack 版本,将 Node 环境降级到 10.15,并为 AppDynamics 包使用其他导入方法,但这似乎是 Appdynamics 库内部的问题?主要问题是,有没有人在使用 Appdynamics 库时遇到过 Webpack 依赖编译问题?你找到解决方法了吗?

任何帮助或线索将不胜感激❤️

标签: node.jswebpackappdynamics

解决方案


解决方案是将“appdynamics”添加到 Webpack 配置中的“externals”:https ://webpack.js.org/configuration/externals/

这允许 AppDynamics 使用默认的 Node.js 需要导入。


推荐阅读