DEV Community

Manav Misra
Manav Misra

Posted on

Answer: Import '.json' extension in ES6 Node.js throws an error

From Node.js version 17.5.0 onward, importing a JSON file is possible using Import Assertions:

import packageFile from "../../package.json" assert { type: "json" }
const {
    name,
    version
  } = packageFile;
  • assert { type: "json" } is mandatory
  • Destructuring such as { name, version } is not possible in the…

Top comments (0)