DEV Community

Manav Misra
Manav Misra

Posted on

1

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay