gpt4 book ai didi

node.js - AppDynamics (Node.js/Express) 依赖项在使用 Webpack 编译时被破坏——任何人都可以确认吗?

转载 作者:太空宇宙 更新时间:2023-11-04 01:34:19 25 4
gpt4 key购买 nike

有人在使用 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依赖编译问题吗?您找到解决方法了吗?

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

最佳答案

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

这允许 AppDynamics 使用默认的 Node.js require import。

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com