Require.JS is for loading AMD modules.
Node.js modules are either ECMAScript modules (which use import
and export
) or CommonJS modules (which use require
and module.exports
).
Even though both AMD and CommonJS modules use a function named require
they are, in general, not compatible. (It is possible to write a module so that it meets the requirements of both AMD and CommonJS but this isn’t too common).
If you want to use Node.js modules in the browser then use a bundler like Webpack or Parcel (but note that they cannot provide APIs that are specific to Node.js, such as the fs
module for reading and writing to and from the file system).