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)