Skip to content

got url.replace is not a function #140

Closed

Description

@Edorka

I'm getting this error while doing a yarn build on a preact-cli project Complete message is

✖ ERROR TypeError: url.replace is not a function
    at /home/edorka/develop/nsp/node_modules/isomorphic-unfetch/index.js:3:36

Probably this is because code doesn't expect to get URL as an object this would be a quick fix:

module.exports = global.fetch = global.fetch || (
	typeof process=='undefined' ? (require('unfetch').default || require('unfetch')) : (function(url, opts) {
                const target = url.href ? url.href : url;
		return require('node-fetch')(target.replace(/^\/\//g,'https://'), opts);
	})
);

Activity

  1. developit commented on Sep 9, 2020

    @developit
    Owner

    Hiya! You're right, Unfetch isn't properly anticipating a URL object.

    The fix is actually even smaller than checking .href - URL.toString() returns the URL string, so we can just do url += '' to cast it to a string.

  2. added a commit that references this issue on Sep 9, 2020
    fb13c71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions