An exquisite npm library for enhanced require in NodeJS
npm install @berakocc/rqx
Why to even use this library?Babel nowadays. And it converts the ES6 modules to RequireJS. The problem is that it uses a property called default in exports object. As an example:
js
// Module.js before Babel
default export ModuleClass {}
// Module.js after Babel
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return !!rightSymbol.hasInstance; } else { return left instanceof right; } }
function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ModuleClass = function ModuleClass() {
_classCallCheck(this, ModuleClass);
};
exports.default = ModuleClass;
// Using compiled Module.js in App.js
// App.js
const ModuleClass = require('./Module')
const myModule = new ModuleClass() // Gives error!
`
But if you had used the rqx, this would've not be a problem for you.
`js
//...Compiling Module
// App.js
const ModuleClass = rqx('Module')
const myModule = new ModuleClass()
`
> In rqx you don't use relative path. node modules and local modules are treated as the same. rqx is a smart module loader. However it always prioritises node modules over local modules.
Contributing`