Import '.json' extension in ES6 Node.js throws an error
You can sill import require
in an ES6 module for Node.js:
import { createRequire } from "module"; // Bring in the ability to create the 'require' method
const require = createRequire(import.meta.url); // construct the require method
const my_json_file = require("path/to/json/your-json-file.json") // use the require method
According to the Node.js ES Modules docs --experimental-json-modules. is required for importing JSON files.
Include the --experimental-json-modules flag for the module to work.
node --experimental-json-modules about.js