Node.js · Middle · Question 65 of 75
Can CommonJS code require() an ES module in modern Node.js?
- 1No, ES modules can only be loaded with
import - 2Yes, but only JSON modules
- ✓Correct answer: Yes, if the ES module has no top-level
await
Explanation
require(esm) was added in recent versions, which made mixing module systems much easier. If the module uses top-level await, use dynamic import().