Skip to content

TypeError: URL is not a constructor in replace-info.js of NPM #34738

@ewrayjohnson

Description

@ewrayjohnson

This occurs with Nodejs 14.7.0 it does not occur with 12.18.3
In NPM CLI on line 14 of replace-info.js an attempt is made to construct a new URL(...), however URL is not a constructor.

Since upgrading Nodejs causes the problem many will consider this a NodeJS bug since the newer version is not backward compatible. I am not sure in what release of Nodejs the change was introduced.

If the bug is in NPM CLI:
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.

See: npm/cli#1658

Metadata

Metadata

Assignees

No one assigned

    Labels

    urlIssues and PRs related to the legacy built-in url module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions