Notes for Webpack users
Webpack is a popular module bundler, used to package JavaScript and Node.js applications. Webpack is designed primarily to take a group of large interdependent modules and bundle them into a smaller set of output artifacts, thus improving the performance of applications.
Webpack attempts to determine dependencies between modules, and removes module functions that it cannot find clear dependencies on. As a result, for a Node application that is using tCell agents, webpack often accidentally removes the tcell-agent
dependency. It is therefore important to manage tcell-agent
explicitly as an external dependency.
The webpack externals
configuration option allows an application to tell webpack explicitly to load node dependencies as standard node external dependencies, rather than try to "inline" only the dependent functions. The accompanying example webpack.config.js
webpack bundle has an existing external, express
, and an added external tcell-agent
. You should always use the externals
format shown in the example.
Example: webpack.config.js file
1const path = require('path');23module.exports = {4target: 'node',5entry: './src/start.ts',6module: {7rules: [8{9test: /\.tsx?$/,10use: 'ts-loader',11}12]13},14resolve: {15extensions: [ ".tsx", ".ts", ".js" ]16},17externals: {18"tcell-agent": "require('tcell-agent')",19"express": "require('express')"20},21output: {22filename: 'bundle.js',23path: path.resolve(__dirname, 'dist')24}25};
Troubleshooting
If the Node agent is not connecting to the tCell cloud and communicating events, do the following:
- Verify that in the output main server file there is an exported
tcell-agent
require. A simple way to verify is to use the standardgrep
tool. For example, if the output file isdist/bundle.js
, then run:This should return a hit withUsing grep to verify a tcell-agent require1grep "tcell-agent" dist/bundle.jsrequire('tcell-agent')
as an export. - Check the
webpack.config.js
file to make sure target is 'node'. - Some complex build and deployment systems have multiple
webpack.config.js
files. Check to make sure ALLwebpack.config.js
files for node application(s) havetcell-agent
in theexternals
list.