使用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依赖项编译问题?您是否找到解决该问题的方法?

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

最佳答案

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

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

关于node.js - 使用Webpack编译的AppDynamics(Node.js/Express)依赖关系已损坏-有人可以确认吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55048208/

10-11 15:02