soyuka / pidusage

Cross-platform process cpu % and memory usage of a PID
MIT License
512 stars 55 forks source link

[BUG] pidusage not compatible with bundling due to dynamic requires in stats.js #153

Closed tabarra closed 1 year ago

tabarra commented 2 years ago

API Platform version(s) affected: 3.0.0

Description
If bundled, it will not be able to detect which platform the lib is running, which will throw xxx is not supported yet error even for supported platforms like win32 and linux.
This issue has also been reported in #152 and #144 , but I decided to create a new issue with the correct title.

How to reproduce
Just try to bundle it with esbuild, webpack, or whatever.

Possible Solution
Replace the dynamic import below with static ones that bundlers can resolve.

let stat
try {
  stat = require('./' + platformToMethod[platform])
} catch (err) {}

Additional Context
PR incoming.