riot / route

Simple isomorphic router
MIT License
212 stars 40 forks source link

Error when compiling webpack #168

Closed damusix closed 1 year ago

damusix commented 1 year ago
ERROR in ./node_modules/@riotjs/route/route.esm.js 729:18-38
Module not found: Error: Can't resolve 'url' in '/Users/alonso/projects/upm/electron-app/node_modules/@riotjs/route'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

Culprit is in route.esm.js

const parseURL = function parseURL() {
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
    args[_key] = arguments[_key];
  }

  return isNode ? require('url').parse(...args) : new URL(...args); // <---
};

This fixes it

const parseURL = function parseURL() {
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
    args[_key] = arguments[_key];
  }

  return new URL(...args); // <---
};

Any reason to require('url') since URL is standard in both Node and Browser?

GianlucaGuarini commented 1 year ago

The legacy Nodejs url module didn't require the base like the URL instance does. It's an ergonomic decision that I will need to re-evaluate in https://github.com/GianlucaGuarini/rawth/

Stay tuned :)

JaredCHall commented 1 year ago

I was able to fix this in webpack 5.75 by running npm install url.

GianlucaGuarini commented 1 year ago

Fixed in v9.0.0