fix: error invalid arg type on WSL systems on url open#118
Closed
kchindam-infy wants to merge 13 commits intonpm:mainfrom
Closed
fix: error invalid arg type on WSL systems on url open#118kchindam-infy wants to merge 13 commits intonpm:mainfrom
kchindam-infy wants to merge 13 commits intonpm:mainfrom
Conversation
wraithgar
reviewed
Sep 5, 2024
| if (platform === 'win32') { | ||
| // spawnWithShell does not do the additional os.release() check, so we | ||
| // have to force the shell here to make sure we treat WSL as windows. | ||
| options.shell = process.env.ComSpec |
Member
There was a problem hiding this comment.
setting options.shell was load bearing here, spawnWithShell needs that behavior.
wraithgar
reviewed
Sep 5, 2024
lib/index.js
Outdated
| // accidentally interpret the first arg as the title, we stick an empty | ||
| // string immediately after the start command | ||
| command = 'start ""' | ||
| command = `${shellCommand} /c start ""` |
Member
There was a problem hiding this comment.
removing options.shell is likely why this had to change. it's not the right solution, you need to keep options.shell set and let the rest of the code build the /c part.
wraithgar
added a commit
that referenced
this pull request
Oct 18, 2024
Here's a more elegant solution for opening URLs from WSL in your favorite browser. It is based on `sensible-browser` which is included in the default distribution for WSL. This avoids issues with the WSL environment, `cmd.exe`. quoting parameters, etc. In WSL, set the default browser using the `BROWSER` variable, for example, ```sh export BROWSER="/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" or export BROWSER="/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" ``` Note: To permanently set the default browser, add the appropriate entry to your shell's RC file, e.g. .bashrc or .zshrc. To launch a URL from the WSL command line: ```sh sensible-browser https://google.com ``` To launch a URL using `promise-spawn`: ```js const promiseSpawn = require('@npmcli/promise-spawn') promiseSpawn.open('https://google.com') ``` Replaces #118 Closes #62 ### Test ``` os: 5.15.153.1-microsoft-standard-WSL2 node: 20.18.0 npm: 10.8.2 ```  --------- Co-authored-by: Gar <wraithgar@github.com>
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix the error invalid arg type on open url in browser on WSL envoirnment.
The npm error on WSL
npm notice Log in on https://registry.npmjs.org/
Login at:
https://www.npmjs.com/login?next=/login/cli/CENSORED
Press ENTER to open in the browser...
npm ERR! code ERR_INVALID_ARG_TYPE
npm ERR! The "file" argument must be of type string. Received undefined
npm ERR! Cannot read properties of undefined (reading 'stdin')
The process.env.ComSpec is undefined in WSL, leading to an incorrect shell configuration. The original command 'start ""' isn't recognized as a valid command in WSL. The fixed implementation correctly constructs the full Windows command, ensuring it works in both regular windows and WSL environments.
References