I've been searching for a solution to this issue without any luck. It seems that the browser doesn't understand commonJS syntax, which is why I get a ReferenceError if I try to load require() like this
let isEven = require('is-even') // ReferenceError: Can't find variable: require
console.log(isEven(6)); // this doesn't run
So, I attempted to switch to ES6 modules as follows:
import isEven from "is-even";
console.log(isEven(6));
However, I encountered the following error in the console:
TypeError: Module specifier, 'is-even' does not start with "/", "./", or "../".
My current workaround is to use a module bundler like Webpack, which allows me to effectively use both syntaxes without any issues. But, I prefer to explore other options because debugging can be challenging with a module bundler since it's hard to pinpoint the code causing errors. Is there an alternative method to transform older JavaScript modules before serving them to the browser, aside from using a module bundler?