Skip to content

fix(plugins): clean up leftover files after plugin uninstall#2458

Open
dirkwa wants to merge 1 commit intoSignalK:masterfrom
dirkwa:fix-plugin-uninstall-cleanup
Open

fix(plugins): clean up leftover files after plugin uninstall#2458
dirkwa wants to merge 1 commit intoSignalK:masterfrom
dirkwa:fix-plugin-uninstall-cleanup

Conversation

@dirkwa
Copy link
Contributor

@dirkwa dirkwa commented Mar 16, 2026

Background

Discord User Tore Dahl repored the issue that a plugin is not removed properly.
https://discord.com/channels/1170433917761892493/1481926436335124633

Summary

When npm remove fails silently, the plugin directory remains in node_modules/ and the dependency stays in package.json. On server restart the plugin loads as if never removed, and running npm install (e.g. after deleting node_modules/) reinstalls it.

Adds cleanupAfterRemove() that runs after npm remove completes to handle this scenario:

  • Removes leftover node_modules/<package> directory
  • Removes the dependency from package.json
  • Clears Node.js require cache for the removed module
  • Deletes plugin config file and data directory

Fixes the issue reported by @torevalley where uninstalled plugins reappeared after npm install.

Manually Tested

  • Added and removed various plugins and verified in ~/.signalk that no remains where left.

@torevalley
Copy link

torevalley commented Mar 17, 2026

Grateful Dirk!!

There just might be one other thing to check, due to testing I have been forced to remove the node-modules folder and re-create it by npm install, and that makes the signalk-fusion-device directory pop-up agaian. Thinking there is some residual inside npm, not beeing a nodejs developer so limited understanding but the package.json in -signalk lists these dependencies...

"dependencies": { "@canboat/visual-analyzer": "^1.20.0", "@mxtommy/kip": "^4.6.0", "@signalk/charts-plugin": "^3.3.0", "@signalk/course-provider": "^1.2.4", "@signalk/freeboard-sk": "^2.19.9", "@signalk/instrumentpanel": "^0.26.0", "@signalk/resources-provider": "^1.5.1", "@signalk/server-admin-ui-react19": "^2.23.1", "@signalk/set-system-time": "^1.5.0", "@signalk/signalk-node-red": "^4.1.1", "@signalk/signalk-to-nmea0183": "^1.13.5", "signalk-aishub-ws": "^1.7.0", "signalk-derived-data": "^1.41.0", "signalk-fusion-device": "^0.0.3", "signalk-n2kais-to-nmea0183": "^2.0.3", "signalk-to-nmea2000": "^2.24.0" },

When npm remove fails silently, the plugin directory remains in
node_modules and the dependency stays in package.json. On next
npm install, the "removed" plugin gets reinstalled.

Add cleanupAfterRemove() that runs after npm remove completes:
- Removes leftover node_modules/<package> directory
- Removes the dependency from package.json
- Clears Node.js require cache for the removed module
- Deletes plugin config file and data directory
@dirkwa dirkwa force-pushed the fix-plugin-uninstall-cleanup branch from 3377a19 to cdde2a3 Compare March 17, 2026 16:14
@dirkwa
Copy link
Contributor Author

dirkwa commented Mar 17, 2026

@torevalley

Good catch, I updated it and now it should remove the dependency even if the remove silently falls.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants