包详细信息

require-esm-as-empty-object

DanielJDufour99CC0-1.00.0.1

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

esm, import, module, require

自述文件

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 {}.

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