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

TypeError: URL is not a constructor in replace-info.js #1658

Closed
ewrayjohnson opened this issue Aug 11, 2020 · 2 comments
Closed

TypeError: URL is not a constructor in replace-info.js #1658

ewrayjohnson opened this issue Aug 11, 2020 · 2 comments
Assignees
Labels
Bug thing that needs fixing Release 6.x work is associated with a specific npm 6 release

Comments

@ewrayjohnson
Copy link

ewrayjohnson commented Aug 11, 2020

This occurs with Nodejs 14.7.0
On line 14 of replace-info.js an attempt is made to construct a new URL(...), however URL is not a constructor.
One fix is to change line 1 to:
const URL = require('url').URL;
Another (possibly better) option to fix is to replace new URL with URL.parse

@aduh95
Copy link
Contributor

aduh95 commented Aug 12, 2020

Or just remove line 1:

const URL = require('url')

Here URL refers to the url built-in module rather than the global URL object. That's unfortunate, the url module is not even used in this module. The following code fails because of that:

const url = new URL(arg)
return url.password === '' ? arg : arg.replace(url.password, '***')

The WHATWG URL object is globally available on Node.js since Node.js 10.0.0, although you still can use require('url').URL it is not a requirement and refers to the same object.

aduh95 added a commit to aduh95/cli that referenced this issue Aug 12, 2020
MylesBorins added a commit to MylesBorins/cli that referenced this issue Aug 12, 2020
The return from `require('url')` is not the URL constructor, that is
exported as `url.URL`. The constructor is generally available as a
global, so this pattern isn't 100% necessary, but this is the best
way to do it based on existing patterns in npm

Refs: nodejs/node#34738
Fixes: npm#1658
@darcyclarke darcyclarke added Bug thing that needs fixing Release 6.x work is associated with a specific npm 6 release labels Aug 13, 2020
@darcyclarke darcyclarke added this to the OSS - Sprint 13 milestone Aug 13, 2020
@claudiahdz
Copy link
Contributor

Thank you for the catch, we'll make the proper changes considering we still have to support Node 6 on npm v6. The fix will be shipped next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 6.x work is associated with a specific npm 6 release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants