fix: `next info` command does not output the versions of `npm` `yarn` and `pnpm` correctly (#71134)
#🐛 Fixed a bug Hello, I've fixed a bug where the `next info` command does not correctly output the versions of `npm`, `yarn`, and `pnpm` especially in **Windows**. ## Why? Although `npm`, `yarn`, and `pnpm` are correctly installed, the `next info` command does not accurately display their versions, as shown in the screenshot below.  ## How? ### 1. Fallback to `execSync` If `execFileSync` throws an error (indicating that the command could not be executed or the output was not valid), the code now attempts to run the same command using `execSync`. This provides a second chance to retrieve the version. ### 2. Error Handling Both `execFileSync` and `execSync` are wrapped in their respective try-catch blocks. If both attempts fail, the function will return `'N/A'`, just like before. This change enhances the robustness of the function by ensuring that it can still retrieve the version information even if the first method fails due to environment variable issues or other reasons related to how the command is executed. > `execSync` and `execFileSync` execute processes in different ways in Node.js. The differences between these two functions can lead to variations in the output of the Package Manager's version. > > `execSync` > > `execSync` accepts commands as strings and executes them in a shell. During this process, all shell environment variables are applied, allowing the command to run with any environment variables related to Package Managers. For example, calling `execSync('npm --version')` will utilize all environment variables associated with the current user's environment, ensuring that `npm` is correctly installed and located. > > `execFileSync` > > `execFileSync`, on the other hand, takes the executable file and its arguments as an array and runs the file directly. This means that it starts the process without going through the shell, so shell environment variables and settings are not applied. Since Package Managers are generally designed to work correctly when executed in a shell, running Package Managers via `execFileSync` may lead to missing environment variables, resulting in incorrect output. ## Result It now works properly.  --- - fixes: I tried to find but no related issues. Co-authored-by:Sam Ko <sam@vercel.com>
Showing
Please
register
or
sign in
to comment