This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Description
ESM cannot load a module "synchronously" with a dynamic specifier. Until we have top-level await, I think we need a supported way to do it. Two use cases:
let env;
if (process.env.NODE_ENV === 'production') {
env = require('./prod.js');
} else {
env = require('./dev.js');
}
let canvas, hasCanvas;
try {
canvas = require('canvas');
hasCanvas = true;
} catch (e) {
hasCanvas = false;
}
I can think of three solutions:
- Explain in the documentation that one has to write the dynamic code in a commonJS module and import it.
- Add
import.meta.require
- Add a builtin module that provides the
require function (npm proposal)