Skip to content

Comments

Fix: Express plugin compatibility for Express 4.x and 5.x#126

Merged
kezhenxu94 merged 2 commits intoapache:masterfrom
thiagomatar:fix-express-plugin-compatibility
Feb 19, 2025
Merged

Fix: Express plugin compatibility for Express 4.x and 5.x#126
kezhenxu94 merged 2 commits intoapache:masterfrom
thiagomatar:fix-express-plugin-compatibility

Conversation

@thiagomatar
Copy link
Contributor

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).

@thiagomatar
Copy link
Contributor Author

Sorry guys, I had to close the other PR because I did something wrong.

@thiagomatar
Copy link
Contributor Author

@wu-sheng Can you check this other one please?

@wu-sheng wu-sheng requested a review from kezhenxu94 February 15, 2025 05:57
@wu-sheng
Copy link
Member

I'm not working on nodejs agent, need to wait for @kezhenxu94 to review.

@wu-sheng
Copy link
Member

And CI should pass, you should have verified the codes through all CI processes locally.

@thiagomatar
Copy link
Contributor Author

Thanks for the reply, I am facing errors while trying to install node 14 on my macbook, there are some issues with the m1 cpus architecture. I will try run the tests in other computer later.

@kezhenxu94 kezhenxu94 added enhancement New feature or request plugin labels Feb 19, 2025
@kezhenxu94 kezhenxu94 added this to the 0.8.0 milestone Feb 19, 2025
@kezhenxu94 kezhenxu94 merged commit bf52544 into apache:master Feb 19, 2025
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants