79318110

Date: 2024-12-30 16:41:14
Score: 0.5
Natty:
Report link

Building on top of the very good answer by @mark-amery:

A simpler way to maintain compatibility between Node.js versions is to use require, which supports JSON files:

import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);

const siblingModule = require(configPath); 

Node.js also caches what's require'd, making this version more consistent with the equivalent import method.

This is supported by all Node.js versions since v12.2.0 and is the solution used by import-from-esm.

Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @mark-amery
Posted by: Pierre Cavin