Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_INVALID_URL with npm alias #1318

Closed
3 tasks done
Cherry opened this issue Aug 25, 2023 · 11 comments · Fixed by #1319
Closed
3 tasks done

ERR_INVALID_URL with npm alias #1318

Cherry opened this issue Aug 25, 2023 · 11 comments · Fixed by #1319
Labels

Comments

@Cherry
Copy link
Contributor

Cherry commented Aug 25, 2023

  • I have searched for similar issues
  • I am using the latest version of npm-check-updates
  • I am using node >= 14.14

Steps to Reproduce

Dependencies:

{
	"dependencies": {
		"request": "npm:postman-request@2.88.1-postman.33"
	}
}

Steps:

  • with above package.json
  • npx npm-check-updates@16.13.0 -i

Current Behavior

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:405:5)
    at Url.parse (node:url:445:17)
    at Object.urlParse [as parse] (node:url:167:13)
    at parse (C:\Users\james\AppData\Roaming\npm\node_modules\npm-check-updates\node_modules\parse-github-url\index.js:27:17)
    at parseGithubUrl (C:\Users\james\AppData\Roaming\npm\node_modules\npm-check-updates\node_modules\parse-github-url\index.js:14:38)
    at isGithubUrl (C:\Users\james\AppData\Roaming\npm\node_modules\npm-check-updates\build\src\lib\version-util.js:396:51)
    at getPackageVersionProtected (C:\Users\james\AppData\Roaming\npm\node_modules\npm-check-updates\build\src\lib\queryVersions.js:57:67)
    at C:\Users\james\AppData\Roaming\npm\node_modules\npm-check-updates\node_modules\p-map\index.js:57:28 {
  input: 'npm:postman-request@2.88.1-postman.33',
  code: 'ERR_INVALID_URL'
}

Expected Behavior

Be able to parse and understand the npm alias. This works in version 7, as per npx npm-check-updates@7.0.0 -i, and reported at #633.

@raineorshine
Copy link
Owner

Hi, thanks for reporting.

What version of node are you on? I'm not yet able to reproduce on node v20, v18, or v16.

@Cherry
Copy link
Contributor Author

Cherry commented Aug 25, 2023

Node v18.17.1, Windows 10. I'm able to consistently reproduce on my machine, interesting 🤔

@raineorshine
Copy link
Owner

raineorshine commented Aug 25, 2023

Hmmm, strange. I ran npm update on npm-check-updates in case there was a regression in a dependency, but it still works for me.

If you'd like to take a stab at this, you could start by running the tests on your machine:

UPDATED:

git clone https://github.com/raineorshine/npm-check-updates
cd npm-check-updates
npm install
npm run build
npm test

@Cherry
Copy link
Contributor Author

Cherry commented Aug 25, 2023

Looks like I got a lot of test failures, hmmm. test.log. But lots of successes too.

If I can do any further debugging on my end, please let me know.

@raineorshine
Copy link
Owner

Oops, I omitted a step. You'll need to run npm run build before running the tests.

@Cherry
Copy link
Contributor Author

Cherry commented Aug 25, 2023

Here's the updated test log. It seems like most were successful, but a couple of failures:
test.log

@raineorshine
Copy link
Owner

raineorshine commented Aug 25, 2023

Thanks. The doctor test failure is a known issue and unrelated. The two bin failures are false negatives caused by the presence of C:\Users\james\package.json. Not relevant to the error you are seeing.

Notably, all of the tests related to parsing npm and GitHub urls are passing. This (plus the fact that the tests pass on Windows in the GitHub action) suggests that the issue is not covered by the tests.

I can add your specific example to the tests and see if the CI can reproduce, but ultimately someone who can reproduce the issue on a local machine will need to identify the issue and open a PR with the fix.

@Cherry
Copy link
Contributor Author

Cherry commented Aug 25, 2023

Thanks for the info, I'll do some more digging to see if I can identify where the issue is!

@Cherry
Copy link
Contributor Author

Cherry commented Aug 25, 2023

The issue appears to be due to parse-github-url throwing an error:

> const parseGithubURL = require('parse-github-url')
undefined
> parseGithubURL('npm:postman-request@2.88.1-postman.33')
Uncaught TypeError [ERR_INVALID_URL]: Invalid URL
    at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
    at new NodeError (node:internal/errors:405:5)
    at Url.parse (node:url:445:17)
    at Object.urlParse [as parse] (node:url:167:13)
    at parse (E:\ncu-test\node_modules\parse-github-url\index.js:27:17)
    at parseGithubUrl (E:\ncu-test\node_modules\parse-github-url\index.js:14:38) {
  input: 'npm:postman-request@2.88.1-postman.33',
  code: 'ERR_INVALID_URL'
}
> parseGithubURL('16.13.1')
Url {
  protocol: null,
  slashes: null,
  auth: null,
  host: 'github.com',
  port: null,
  hostname: null,
  hash: null,
  search: null,
  query: null,
  pathname: '16.13.1',
  path: '16.13.1',
  href: '16.13.1',
  filepath: null,
  owner: null,
  name: null,
  repo: null,
  branch: 'master',
  repository: null
}
>

which appears to be due to url.parse doing this under the hood:

> url.parse("npm:postman-request@2.88.1-postman.33")
Uncaught TypeError [ERR_INVALID_URL]: Invalid URL
    at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
    at new NodeError (node:internal/errors:405:5)
    at Url.parse (node:url:445:17)
    at Object.urlParse [as parse] (node:url:167:13) {
  input: 'npm:postman-request@2.88.1-postman.33',
  code: 'ERR_INVALID_URL'
}
> url.parse("16.13.1")
Url {
  protocol: null,
  slashes: null,
  auth: null,
  host: null,
  port: null,
  hostname: null,
  hash: null,
  search: null,
  query: null,
  pathname: '16.13.1',
  path: '16.13.1',
  href: '16.13.1'
}

parseGithubURL('npm:chalk@1.0.0') returns null, whereas parseGithubURL('npm:chalk@1.0.0-dasda.2') throws an error, so it seems this library doesn't handle complex version strings very well.

The easiest solution would be to try...catch this and in my testing it does resolve it. I'll also add a couple of tests to catch this moving forward. PR to fix incoming soon!

@Cherry
Copy link
Contributor Author

Cherry commented Aug 25, 2023

PR to fix at #1319. Thanks for working through that with me!

@Cherry
Copy link
Contributor Author

Cherry commented Aug 25, 2023

Looks like this is a regression with Node 18.17 specifically: nodejs/node#49330

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants