Skip to content

Require ES Modules as an Empty Object. A workaround for "Error [ERR_REQUIRE_ESM]: require() of ES Module not supported."

License

Notifications You must be signed in to change notification settings

DanielJDufour/require-esm-as-empty-object

Repository files navigation

require-esm-as-empty-object

Require ES Modules as an Empty Object.

A workaround for "Error [ERR_REQUIRE_ESM]: require() of ES Module not supported."

how does it work?

Intercepts failing require(NAME_OF_ES_MODULE) calls and returns {}.

install

npm install require-esm-as-empty-object

usage

using r flag

// app.js
const lru = require("quick-lru"); // an ES Module

console.log(lru);
{}
...
node -r require-esm-as-empty-object app.js

placing at top of file

// app.js
// place at top of file before requiring an ES Module
require("require-esm-as-empty-object");

const lru = require("quick-lru");
...
node app.js

About

Require ES Modules as an Empty Object. A workaround for "Error [ERR_REQUIRE_ESM]: require() of ES Module not supported."

Resources

License

Stars

Watchers

Forks

Packages

No packages published