Skip to content

Comments

Fix: Ensure compatibility with Express 4.x and 5.x in ExpressPlugin#125

Closed
thiagomatar wants to merge 3 commits intoapache:masterfrom
thiagomatar:patch-1
Closed

Fix: Ensure compatibility with Express 4.x and 5.x in ExpressPlugin#125
thiagomatar wants to merge 3 commits intoapache:masterfrom
thiagomatar:patch-1

Conversation

@thiagomatar
Copy link
Contributor

@thiagomatar thiagomatar commented Feb 14, 2025

We are evaluating the use of SkyWalking in our company, and I have started some proof-of-concept tests to evaluate the agents.
I created a new project using Node.js/NestJS and the SkyWalking Node.js agent, following the instructions provided on the NodeJS Agent page to install it in the project.

Versions used:

  • Node.js: 22.14.0
  • NestJS: 11.0.1
  • Express: 5.0.1

Upon initializing the project, I encountered the following error message:

{
  message: 'Error installing plugin express *',
  level: 'error',
  file: '...node_modules/skywalking-backend-js/lib/core/PluginInstaller.js'
}

After investigating the code, I identified the root cause.
In the ExpressPlugin.js file, line 39:

var router = (_b = (_a = installer.require) === null || _a === void 0 ? void 0 : _a.call(installer, 'express/lib/router')) !== null && _b !== void 0 ? _b : require('express/lib/router');

The error Cannot find module 'express/lib/router' occurs because the installed version of Express no longer has this folder structure (express/lib/router). This is due to recent versions of Express reorganizing their modules differently.

To address this issue, I am adding compatibility for both older and newer versions of Express:

  1. First, attempt to load express.Router() (used in Express 5+).
  2. If that fails, attempt to load express/lib/router (used in Express 4.x).

@apache apache deleted a comment from a526672351 Feb 14, 2025
@apache apache deleted a comment from tkNobug Feb 14, 2025
@wu-sheng wu-sheng added this to the 0.8.0 milestone Feb 14, 2025
@wu-sheng wu-sheng added the enhancement New feature or request label Feb 14, 2025
Copy link
Contributor Author

@thiagomatar thiagomatar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplifying the solution

@thiagomatar
Copy link
Contributor Author

sorry guys I did a mistake and I will open other PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants