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

got url.replace is not a function #140

Closed
Edorka opened this issue Aug 31, 2020 · 1 comment · Fixed by #141
Closed

got url.replace is not a function #140

Edorka opened this issue Aug 31, 2020 · 1 comment · Fixed by #141

Comments

@Edorka
Copy link

Edorka commented Aug 31, 2020

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);
	})
);
@developit
Copy link
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.

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

Successfully merging a pull request may close this issue.

2 participants