nut-tree / nut.js

Native UI testing / controlling with node
https://nutjs.dev
2.27k stars 129 forks source link

Errors when bundling using Webpack #546

Closed code-r-man closed 10 months ago

code-r-man commented 11 months ago

Version 3.1.2

Short overview When trying to bundle the library using Webpack the process fails with multiple errors.

Issue occurs on

node version: 14.21.3

OS type and version: Windows 10

Detailed error description

WARNING in ./node_modules/@nut-tree/libnut-darwin/permissionCheck.js 7:24-65
Module not found: Error: Can't resolve '@nut-tree/node-mac-permissions' in 'C:\Users\Nix\Documents\del\node_modules\@nut-tree\libnut-darwin'
 @ ./node_modules/@nut-tree/libnut-darwin/index.js 3:13-41
 @ ./node_modules/@nut-tree/libnut/index.js 8:10-44
 @ ./node_modules/@nut-tree/nut-js/dist/lib/provider/native/libnut-mouse.class.js 3:15-42
 @ ./node_modules/@nut-tree/nut-js/dist/lib/provider/provider-registry.class.js 7:45-83
 @ ./node_modules/@nut-tree/nut-js/dist/index.js 34:50-99
 @ ./index.js 1:26-53

WARNING in ./node_modules/@nut-tree/libnut-linux/permissionCheck.js 7:24-65
Module not found: Error: Can't resolve '@nut-tree/node-mac-permissions' in 'C:\Users\Nix\Documents\del\node_modules\@nut-tree\libnut-linux'
 @ ./node_modules/@nut-tree/libnut-linux/index.js 3:13-41
 @ ./node_modules/@nut-tree/libnut/index.js 6:10-43
 @ ./node_modules/@nut-tree/nut-js/dist/lib/provider/native/libnut-mouse.class.js 3:15-42
 @ ./node_modules/@nut-tree/nut-js/dist/lib/provider/provider-registry.class.js 7:45-83
 @ ./node_modules/@nut-tree/nut-js/dist/index.js 34:50-99
 @ ./index.js 1:26-53

WARNING in ./node_modules/@nut-tree/libnut-win32/permissionCheck.js 7:24-65
Module not found: Error: Can't resolve '@nut-tree/node-mac-permissions' in 'C:\Users\Nix\Documents\del\node_modules\@nut-tree\libnut-win32'
 @ ./node_modules/@nut-tree/libnut-win32/index.js 3:13-41
 @ ./node_modules/@nut-tree/libnut/index.js 4:10-43
 @ ./node_modules/@nut-tree/nut-js/dist/lib/provider/native/libnut-mouse.class.js 3:15-42
 @ ./node_modules/@nut-tree/nut-js/dist/lib/provider/provider-registry.class.js 7:45-83
 @ ./node_modules/@nut-tree/nut-js/dist/index.js 34:50-99
 @ ./index.js 1:26-53

Full code sample to reproduce Import the library in a file (index.js) like so: const { keyboard, Key } = require("@nut-tree/nut-js"); and try to bundle it using Webpack:

  1. npm install webpack webpack-cli --save-dev
  2. npm i @nut-tree/nut-js --save
  3. npx webpack-cli build --entry ./index.js --target electron-main --output-path ./index.min.js --mode production

Additional content

Please provide any (mandatory) additional data to reproduce the error (Dockerfiles etc.)

code-r-man commented 11 months ago

Interestingly version 2.3.0 does not cause this issue - it starts happening at version 3.0.0 and above.

s1hofmann commented 11 months ago

Hi @code-r-man πŸ‘‹

older versions of nut.js do not include this optional dependency that is only relevant on macOS. Code wise it is also guarded that it shouldn't get required on other platforms, so I'm wondering what Webpack is doing here. This is the first report of this behaviour, so I'd have to take a closer look.

Best regards

Simon

JuraJuki commented 10 months ago

I am having the same issue. Those packages cannot be installed since it is an unsupported platform (Windows but it needs mac to install it)

npm ERR! notsup Unsupported platform for @nut-tree/node-mac-permissions@2.2.1: wanted {"os":"darwin"} (current: {"os":"win32"})

any updates on this?

s1hofmann commented 10 months ago

Hi @JuraJuki πŸ‘‹

in that case nothing will happen from a nut.js perspective.

@nut-tree/node-mac-permissions is an optional dependency and does not cause installation to fail.

If this is not properly handled in the WebPack build it’s a WebPack problem.