swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.53k stars 8.96k forks source link

Why does installing swagger-ui require Visual Studio and a C++ toolchain? #9001

Closed kaiyoma closed 1 year ago

kaiyoma commented 1 year ago

Q&A (please complete the following information)

Describe the bug you're encountering

I can't install this dependency because it requires Visual C++. Why on earth does a simple UI library require GBs of C++ tools to be installed?

Progress: resolved 1790, reused 1742, downloaded 26, added 79, done
node_modules/.pnpm/tree-sitter-json@0.20.0/node_modules/tree-sitter-json: Running install script, failed in 3.9s/.pnpm/tree-sitter-yaml@0.5.0/node_modules/tree-sitter-yaml: Running install script...
.../node_modules/tree-sitter-json install$ node-gyp rebuild
│ C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\tree-sitter-json@0.20.0\node_modules\tree-si
│ gyp info it worked if it ends with ok
│ gyp info using node-gyp@9.3.1
│ gyp info using node@18.16.0 | win32 | x64
│ gyp info find Python using Python version 3.11.4 found at "C:\Users\kgetz\AppData\Local\Microsof
│ gyp ERR! find VS
│ gyp ERR! find VS msvs_version not set from command line or npm config
│ gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
│ gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running wi
│ gyp ERR! find VS looking for Visual Studio 2015
│ gyp ERR! find VS - not found
│ gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
│ gyp ERR! find VS
│ gyp ERR! find VS **************************************************************
│ gyp ERR! find VS You need to install the latest version of Visual Studio
│ gyp ERR! find VS including the "Desktop development with C++" workload.
│ gyp ERR! find VS For more information consult the documentation at:
│ gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
│ gyp ERR! find VS **************************************************************
│ gyp ERR! find VS
│ gyp ERR! configure error
│ gyp ERR! stack Error: Could not find any Visual Studio installation to use
│ gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\kgetz\AppData\Roaming\nv
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at ChildProcess.exithandler (node:child_process:427:5)
│ gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
│ gyp ERR! stack     at maybeClose (node:internal/child_process:1091:16)
│ gyp ERR! System Windows_NT 10.0.22621
│ gyp ERR! command "C:\\Program Files\\Node.js\\node.exe" "C:\\Users\\kgetz\\AppData\\Roaming\\nvm
│ gyp ERR! cwd C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\tree-sitter-json@0.20.0\node_mo
│ gyp ERR! node -v v18.16.0
│ gyp ERR! node-gyp -v v9.3.1
│ gyp ERR! not ok
└─ Failed in 3.9s at C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\tree-sitter-json@0.20.0\node_modules\tree-sitter-json
node_modules/.pnpm/tree-sitter-yaml@0.5.0/node_modules/tree-sitter-yaml: Running install script...
node_modules/.pnpm/tree-sitter@0.20.4/node_modules/tree-sitter: Running install script, failed in 3.8sLIFECYCLE  Command failed with exit code 1.
.../node_modules/tree-sitter install$ prebuild-install || node-gyp rebuild
│ prebuild-install warn install No prebuilt binaries found (target=18.16.0 runtime=node arch=x64 l
│ C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\tree-sitter@0.20.4\node_modules\tree-sitter>
│ gyp info it worked if it ends with ok
│ gyp info using node-gyp@9.3.1
│ gyp info using node@18.16.0 | win32 | x64
│ gyp info find Python using Python version 3.11.4 found at "C:\Users\kgetz\AppData\Local\Microsof
│ gyp ERR! find VS
│ gyp ERR! find VS msvs_version not set from command line or npm config
│ gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
│ gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running wi
│ gyp ERR! find VS looking for Visual Studio 2015
│ gyp ERR! find VS - not found
│ gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
│ gyp ERR! find VS
│ gyp ERR! find VS **************************************************************
│ gyp ERR! find VS You need to install the latest version of Visual Studio
│ gyp ERR! find VS including the "Desktop development with C++" workload.
│ gyp ERR! find VS For more information consult the documentation at:
│ gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
│ gyp ERR! find VS **************************************************************
node_modules/.pnpm/tree-sitter-yaml@0.5.0/node_modules/tree-sitter-yaml: Running install script, failed in 3.9sconfigure error
.../node_modules/tree-sitter-yaml install$ node-gyp rebuild
│ C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\tree-sitter-yaml@0.5.0\node_modules\tree-sit
│ gyp info it worked if it ends with ok
│ gyp info using node-gyp@9.3.1
│ gyp info using node@18.16.0 | win32 | x64ata\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp info find Python using Python version 3.11.4 found at "C:\Users\kgetz\AppData\Local\Microsof
│ gyp ERR! find VS
│ gyp ERR! find VS msvs_version not set from command line or npm config
│ gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt5)
│ gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running wi
│ gyp ERR! find VS looking for Visual Studio 2015
│ gyp ERR! find VS - not found
│ gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8ata\\Roaming\\nvm
│ gyp ERR! find VS
│ gyp ERR! find VS **************************************************************
│ gyp ERR! find VS You need to install the latest version of Visual Studio
│ gyp ERR! find VS including the "Desktop development with C++" workload.
│ gyp ERR! find VS For more information consult the documentation at:
│ gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
│ gyp ERR! find VS **************************************************************
│ gyp ERR! find VS
│ gyp ERR! configure error
│ gyp ERR! stack Error: Could not find any Visual Studio installation to use
│ gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\kgetz\AppData\Roaming\nv
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at ChildProcess.exithandler (node:child_process:427:5)
│ gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
│ gyp ERR! stack     at maybeClose (node:internal/child_process:1091:16)
│ gyp ERR! System Windows_NT 10.0.22621
│ gyp ERR! command "C:\\Program Files\\Node.js\\node.exe" "C:\\Users\\kgetz\\AppData\\Roaming\\nvm
│ gyp ERR! cwd C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\tree-sitter-yaml@0.5.0\node_mod
│ gyp ERR! node -v v18.16.0
│ gyp ERR! node-gyp -v v9.3.1
│ gyp ERR! not ok
└─ Failed in 3.9s at C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\tree-sitter-yaml@0.5.0\node_modules\tree-sitter-yaml
node_modules/.pnpm/tree-sitter@0.20.4/node_modules/tree-sitter: Running install script, failed in 3.8s
.../node_modules/tree-sitter install$ prebuild-install || node-gyp rebuild
│ prebuild-install warn install No prebuilt binaries found (target=18.16.0 runtime=node arch=x64 l
│ C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\tree-sitter@0.20.4\node_modules\tree-sitter>
│ gyp info it worked if it ends with ok
│ gyp info using node-gyp@9.3.1
│ gyp info using node@18.16.0 | win32 | x64
│ gyp info find Python using Python version 3.11.4 found at "C:\Users\kgetz\AppData\Local\Microsof
│ gyp ERR! find VS
│ gyp ERR! find VS msvs_version not set from command line or npm config
│ gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
│ gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running wi
│ gyp ERR! find VS looking for Visual Studio 2015
│ gyp ERR! find VS - not found
│ gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
│ gyp ERR! find VS
│ gyp ERR! find VS **************************************************************
│ gyp ERR! find VS You need to install the latest version of Visual Studio
│ gyp ERR! find VS including the "Desktop development with C++" workload.
│ gyp ERR! find VS For more information consult the documentation at:
│ gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
│ gyp ERR! find VS **************************************************************
│ gyp ERR! find VS
│ gyp ERR! configure error
│ gyp ERR! stack Error: Could not find any Visual Studio installation to use
│ gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\kgetz\AppData\Roaming\nv
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at C:\Users\kgetz\AppData\Roaming\nvm\v18.16.0\node_modules\pnpm\dist\node_mo
│ gyp ERR! stack     at ChildProcess.exithandler (node:child_process:427:5)
│ gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
│ gyp ERR! stack     at maybeClose (node:internal/child_process:1091:16)
│ gyp ERR! System Windows_NT 10.0.22621
│ gyp ERR! command "C:\\Program Files\\Node.js\\node.exe" "C:\\Users\\kgetz\\AppData\\Roaming\\nvm
│ gyp ERR! cwd C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\tree-sitter@0.20.4\node_modules
│ gyp ERR! node -v v18.16.0
│ gyp ERR! node-gyp -v v9.3.1
│ gyp ERR! not ok
└─ Failed in 3.8s at C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\tree-sitter@0.20.4\node_modules\tree-sitter
 ELIFECYCLE  Command failed with exit code 1.
char0n commented 1 year ago

From what I see, you're using pnpm. I'm not sure how it handles optionalDependencies as I couldn't find documentation about it.

I'll explain how the SwaggerUI@5 works with npm.

SwaggerUI@5 is using swagger-client which under the hood uses ApiDOM to facilitate OpenAPI 3.1.0 definition resolution. Number of dependencies of ApiDOM are marked as optional like (tree-sitter), and if they fail to install, SwaggerUI will work just fine without them. If optional dependencies fail to install, in npm you just get one line message related to failed optional dependency install. The overall installation will proceed successfully.

More info in: https://docs.npmjs.com/cli/v9/configuring-npm/package-json#optionaldependencies

kaiyoma commented 1 year ago

@char0n Ah, this is very helpful, thank you! I'll raise an issue with pnpm.

KostyaTretyak commented 1 year ago

I'm using yarn and it also produces very ugly logs, and it does this with any package installation or removal. Please fix this if possible. I use swagger-ui in some of my packages that are published on npmjs.com and every user sees these logs:

yarn logs ```text yarn install v1.22.19 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... [4/4] Building fresh packages... [-/5] ⠈ waiting... [2/5] ⠈ tree-sitter [3/5] ⠈ tree-sitter-json [4/5] ⠈ tree-sitter-yaml warning Error running install script for optional dependency: "/srv/git/ditsmod/ditsmod/node_modules/tree-sitter-json: Command failed. Exit code: 1 Command: node-gyp rebuild Arguments: Directory: /srv/git/ditsmod/ditsmod/node_modules/tree-sitter-json Output: gyp info it worked if it ends with ok gyp info using node-gyp@9.4.0 gyp info using node@18.17.1 | linux | x64 gyp info find Python using Python version 3.10.12 found at \"/usr/bin/python3\" gyp info spawn /usr/bin/python3 gyp info spawn args [ gyp info spawn args '/srv/git/ditsmod/ditsmod/node_modules/node-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/srv/git/ditsmod/ditsmod/node_modules/tree-sitter-json/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/srv/git/ditsmod/ditsmod/node_modules/node-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/home/me/.cache/node-gyp/18.17.1/include/node/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/home/me/.cache/node-gyp/18.17.1', gyp info spawn args '-Dnode_gyp_dir=/srv/git/ditsmod/ditsmod/node_modules/node-gyp', gyp info spawn args '-Dnode_lib_file=/home/me/.cache/node-gyp/18.17.1/<(target_arch)/node.lib', gyp info spawn args '-Dmodule_root_dir=/srv/git/ditsmod/ditsmod/node_modules/tree-sitter-json', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' gyp info spawn args ] gyp ERR! build error gyp ERR! stack Error: not found: make gyp ERR! stack at getNotFoundError (/srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:10:17) gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:57:18 gyp ERR! stack at new Promise () gyp ERR! stack at step (/srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:54:21) gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:71:22 gyp ERR! stack at new Promise () gyp ERR! stack at subStep (/srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:69:33) gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:80:22 gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/isexe/index.js:42:5 gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/isexe/mode.js:8:5 gyp ERR! System Linux 6.2.0-26-generic gyp ERR! command \"/home/me/.nvm/versions/node/v18.17.1/bin/node\" \"/srv/git/ditsmod/ditsmod/node_modules/.bin/node-gyp\" \"rebuild\" gyp ERR! cwd /srv/git/ditsmod/ditsmod/node_modules/tree-sitter-json [-/5] ⠁ waiting... [2/5] ⠁ tree-sitter [-/5] ⠁ waiting... [4/5] ⠁ tree-sitter-yaml warning Error running install script for optional dependency: "/srv/git/ditsmod/ditsmod/node_modules/tree-sitter-yaml: Command failed. Exit code: 1 Command: node-gyp rebuild Arguments: Directory: /srv/git/ditsmod/ditsmod/node_modules/tree-sitter-yaml Output: gyp info it worked if it ends with ok gyp info using node-gyp@9.4.0 gyp info using node@18.17.1 | linux | x64 gyp info find Python using Python version 3.10.12 found at \"/usr/bin/python3\" gyp info spawn /usr/bin/python3 gyp info spawn args [ gyp info spawn args '/srv/git/ditsmod/ditsmod/node_modules/node-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/srv/git/ditsmod/ditsmod/node_modules/tree-sitter-yaml/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/srv/git/ditsmod/ditsmod/node_modules/node-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/home/me/.cache/node-gyp/18.17.1/include/node/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/home/me/.cache/node-gyp/18.17.1', gyp info spawn args '-Dnode_gyp_dir=/srv/git/ditsmod/ditsmod/node_modules/node-gyp', gyp info spawn args '-Dnode_lib_file=/home/me/.cache/node-gyp/18.17.1/<(target_arch)/node.lib', gyp info spawn args '-Dmodule_root_dir=/srv/git/ditsmod/ditsmod/node_modules/tree-sitter-yaml', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' gyp info spawn args ] gyp ERR! build error gyp ERR! stack Error: not found: make gyp ERR! stack at getNotFoundError (/srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:10:17) gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:57:18 gyp ERR! stack at new Promise () gyp ERR! stack at step (/srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:54:21) gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:71:22 gyp ERR! stack at new Promise () gyp ERR! stack at subStep (/srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:69:33) gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:80:22 gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/isexe/index.js:42:5 gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/isexe/mode.js:8:5 gyp ERR! System Linux 6.2.0-26-generic gyp ERR! command \"/home/me/.nvm/versions/node/v18.17.1/bin/node\" \"/srv/git/ditsmod/ditsmod/node_modules/.bin/node-gyp\" \"rebuild\" gyp ERR! cwd /srv/git/ditsmod/ditsmod/node_modules/tree-sitter-yaml [-/5] ⢀ waiting... [2/5] ⢀ tree-sitter [-/5] ⢀ waiting... [-/5] ⢀ waiting... warning Error running install script for optional dependency: "/srv/git/ditsmod/ditsmod/node_modules/tree-sitter: Command failed. Exit code: 1 Command: prebuild-install || node-gyp rebuild Arguments: Directory: /srv/git/ditsmod/ditsmod/node_modules/tree-sitter Output: prebuild-install warn install No prebuilt binaries found (target=18.17.1 runtime=node arch=x64 libc= platform=linux) gyp info it worked if it ends with ok gyp info using node-gyp@9.4.0 gyp info using node@18.17.1 | linux | x64 gyp info find Python using Python version 3.10.12 found at \"/usr/bin/python3\" gyp info spawn /usr/bin/python3 gyp info spawn args [ gyp info spawn args '/srv/git/ditsmod/ditsmod/node_modules/node-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/srv/git/ditsmod/ditsmod/node_modules/tree-sitter/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/srv/git/ditsmod/ditsmod/node_modules/node-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/home/me/.cache/node-gyp/18.17.1/include/node/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/home/me/.cache/node-gyp/18.17.1', gyp info spawn args '-Dnode_gyp_dir=/srv/git/ditsmod/ditsmod/node_modules/node-gyp', gyp info spawn args '-Dnode_lib_file=/home/me/.cache/node-gyp/18.17.1/<(target_arch)/node.lib', gyp info spawn args '-Dmodule_root_dir=/srv/git/ditsmod/ditsmod/node_modules/tree-sitter', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' gyp info spawn args ] gyp ERR! build error gyp ERR! stack Error: not found: make gyp ERR! stack at getNotFoundError (/srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:10:17) gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:57:18 gyp ERR! stack at new Promise () gyp ERR! stack at step (/srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:54:21) gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:71:22 gyp ERR! stack at new Promise () gyp ERR! stack at subStep (/srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:69:33) gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/node-gyp/node_modules/which/which.js:80:22 gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/isexe/index.js:42:5 gyp ERR! stack at /srv/git/ditsmod/ditsmod/node_modules/isexe/mode.js:8:5 gyp ERR! System Linux 6.2.0-26-generic gyp ERR! command \"/home/me/.nvm/versions/node/v18.17.1/bin/node\" \"/srv/git/ditsmod/ditsmod/node_modules/.bin/node-gyp\" \"rebuild\" gyp ERR! cwd /srv/git/ditsmod/ditsmod/node_modules/tree-sitter success Saved lockfile. Done in 11.86s. ```
YOU54F commented 1 year ago

every user sees these logs:

I don't think every user would

Error: not found: make

You need to install make, that error is from node-gyp which is trying to build native modules.

ps. you can stop post install hooks from running with --ignore-scripts. quite a few users do this already.

I note there are prebuilt binaries on github for tree-sitter anyway

https://github.com/tree-sitter/tree-sitter/releases/tag/v0.20.8

so there isn't necessarily a need for these to built on the end users computer, tree-sitter could allow these to be fetched from github on install time (there is a prebuildify plugin for that) but that won't work with --ignore-scripts either.

Hope that helps a bit :)

KostyaTretyak commented 1 year ago

I don't think every user would

@YOU54F, yes, but no. I'm running Ubuntu 22.04 and only install the programs I need as a TypeScript web developer. I understand that I can install make, but I suspect that 99% of users who download packages from npmjs.com have the same programs as me (+/-).

YOU54F commented 1 year ago

Why on earth does a simple UI library require GBs of C++ tools to be installed?

It's a known documented thing in the node ecosystem for packages that require native modules.

See electrons docs

https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules

YOU54F commented 1 year ago

I don't think every user would

@YOU54F, yes, but no. I'm running Ubuntu 22.04 and only install the programs I need as a TypeScript web developer. I understand that I can install make, but I suspect that 99% of users who download packages from npmjs.com have the same programs as me (+/-).

I'd argue with your stats personally, it's a thing in the javascript ecosystem.

it's not overly common, but considering your a ts web developer, I assume you've worked with electron.

https://github.com/nodejs/node-gyp

https://nodejs.org/api/addons.html

https://blog.risingstack.com/writing-native-node-js-modules/

YOU54F commented 1 year ago

ps. I also help maintain pact-js, we prebuild our native modules (we leverage rust code via a shared library to extend the power of our JS code) - we used to require our users to build these, but it did cause issues for a small percentage.

It was enough for me to prebuild and package the native modules into the npm package (but it inflated the package size) - it's all a set of trade-offs :(

char0n commented 1 year ago

I'm using yarn and it also produces very ugly logs, and it does this with any package installation or removal. Please fix this if possible. I use swagger-ui in some of my packages that are published on npmjs.com and every user sees these logs:

Hi @KostyaTretyak,

We've invested considerable amount of time to solve this so that we don't see any ugly long error logs. In latest versions of npm (9.8.0), the failing optional dependency install will produce just one single overlook-able line in the install log. That's why we settled for this current solution - optionalDepedencies that might fail to install, but overall installation will not fail.

If you don't want to see those error in your project there is a simple solution documented in swagger-client documentation:

https://github.com/swagger-api/swagger-js/blob/master/docs/usage/installation.md#installation

image

In yarn, selective dependency resolutions works in the same way. Inside your README file, in installation instructions sections, you'll suggest people to do the override or resolution (yarn) in order to avoid seeing the optional dependency installation failure.

Another way to remedy this is to disassemble the https://github.com/swagger-api/apidom/tree/main/packages/apidom-reference package (used by swagger-client/swagger-ui and causing these failed install errors) into many more packages, and then assemble those new packages back to use-case based packages, one of which will be for swagger-ui usecase, which doesn't actually need tree-sitter. But this would require significant amount of work, it will increase the complexity of ApiDOM utilization and benefits are questionable.

IMHO concept of optionalDepedencies exists to solve exactly the issues we're having with https://github.com/swagger-api/apidom/tree/main/packages/apidom-reference. It's unfortunate that yarn is producing these big logs, instead of one line notice.

If you have any suggestions, I'm trilled to hear them, as unfortunately I've run out of new ideas, except for the idea of disassembling the apidom-reference package.

KostyaTretyak commented 1 year ago

@char0n, first of all, thank you for taking the time to answer me, even when I ask questions in closed issues.

If you don't want to see those error in your project there is a simple solution documented in swagger-client documentation

I tried it, but for some reason it doesn't work:

  "resolutions": {
    "@swagger-api/apidom-reference/@swagger-api/apidom-ns-asyncapi-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-api-design-systems-json": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-asyncapi-json-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-json": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-json-3-0": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-json-3-1": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-yaml-1-2": "yarn:-@0.0.1"
  }

And this doesn't work:

  "resolutions": {
    "@swagger-api/apidom-ns-asyncapi-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-api-design-systems-json": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-asyncapi-json-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-json": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-json-3-0": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-json-3-1": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-yaml-1-2": "yarn:-@0.0.1"
  }

And with npm: in version also doesn't work.

char0n commented 1 year ago

I tried it, but for some reason it doesn't work:

@KostyaTretyak I'm not sure about yarn resolution syntax (as I use npm), but according to https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/#toc-how-to-use-it it's correct. Not sure about yarn:-@0.0.1 as well, in a scene if this syntax is supported in yarn.

Anyway this overrides/resolutions are meant for your downstream consumers (people using your package). They need to use this override to get rid of the errors. If you put in inside your package, it has no effect downstream.

KostyaTretyak commented 1 year ago

Please tell me which version of swagger-ui does not have these optional dependencies? I tried downgrading to swagger-ui@^3.0.0 but it still has those dependencies.

char0n commented 1 year ago

These optional dependencies come from https://github.com/swagger-api/apidom and https://www.npmjs.com/package/swagger-client respectively.

If you're fixated to remove the errors from you package, you https://www.npmjs.com/package/swagger-ui-dist which contains build fragments of already pre-built SwaggerU and doesn't install anything.

Here is a documentation of what each fragment is: https://github.com/swagger-api/swagger-ui/issues/7831#issue-1128241346

badamik commented 2 months ago

@char0n, first of all, thank you for taking the time to answer me, even when I ask questions in closed issues.

If you don't want to see those error in your project there is a simple solution documented in swagger-client documentation

I tried it, but for some reason it doesn't work:

  "resolutions": {
    "@swagger-api/apidom-reference/@swagger-api/apidom-ns-asyncapi-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-api-design-systems-json": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-asyncapi-json-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-json": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-json-3-0": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-json-3-1": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "yarn:-@0.0.1",
    "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-yaml-1-2": "yarn:-@0.0.1"
  }

And this doesn't work:

  "resolutions": {
    "@swagger-api/apidom-ns-asyncapi-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-api-design-systems-json": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-asyncapi-json-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-json": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-json-3-0": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-json-3-1": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "yarn:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-yaml-1-2": "yarn:-@0.0.1"
  }

And with npm: in version also doesn't work.

For me adding it like this to package.json removed the error from logs. (I'm using yarn)


  "resolutions": {
    "@swagger-api/apidom-ns-asyncapi-2": "npm:-@0.0.1",
    "@swagger-api/apidom-ns-openapi-2": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-api-design-systems-json": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-asyncapi-json-2": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-json": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-json-2": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-yaml-2": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-json-3-0": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-json-3-1": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-workflows-json-1": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-workflows-yaml-1": "npm:-@0.0.1",
    "@swagger-api/apidom-parser-adapter-yaml-1-2": "npm:-@0.0.1"
  }```