balena-io-modules / drivelist

List all connected drives in your computer, in all major operating systems
Apache License 2.0
242 stars 90 forks source link

warning: 'NSArray' may not respond to...' when working with electron. #403

Open bennik88 opened 2 years ago

bennik88 commented 2 years ago

I tried all possible things to make drivelist compatible with electron but I always end up with the same warning when trying to rebuild native Node.js modules with electron-rebuild.

Error:

⠹ Building module: drivelist, Completed: 0../src/darwin/REDiskList.m:29:13: warning: 'NSArray' may not respond to 'sortUsingSelector:'
    [_disks sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
     ~~~~~~ ^
1 warning generated.

Is there any fix I'm not seeing? I like working with drivelist and it would be great to use it.

zwhitchcox commented 2 years ago

@bennik88 Hi, can you try rolling back to 9.2.4 and seeing if you get the same error? If you still get the same error, it's just warning and is probably ok, as it's been used in production for several years.

bennik88 commented 2 years ago

Hi @zwhitchcox thank you for your fast response.

I'm installing the package to/release/app $ npm install drivelist@9.2.4 After that I run $(npm bin)/electron-rebuild

But I get the same error when rebuilding

⠇ Building module: drivelist, Completed: 0../src/darwin/REDiskList.m:29:13: warning: 'NSArray' may not respond to 'sortUsingSelector:'
    [_disks sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
     ~~~~~~ ^
1 warning generated.

I can't even start the app with npm start after that because I get the following error message:

Electron encountered an error

Error: Module did not self-register: '/Users/benjamin/Desktop/electron-hard-drive-manager/release/app/node_modules/drivelist/build/Release/drivelist.node'.
at process.func [as dlopen] (node:electron/js2c/asar_bundle:5:1812)
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1199:18)
at Object.func [as .node] (node:electron/js2c/asar_bundle:5:1812)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:829:12)
at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
at Function.Module._load (/Users/benjamin/Desktop/electron-hard-drive-manager/node_modules/runtime-required/runtime-required.js:34:23)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:102:18)
at bindings (/Users/benjamin/Desktop/electron-hard-drive-manager/release/app/node_modules/bindings/bindings.js:112:48

Also is it possible to use import instead of require?