i was configuring a rollup.config.mjs file and this is how i used to import json files
import packageJson from "./package.json" assert { type: "json" };
as far i have tested it works in node 20 without any errors but a warning of
(node:34471) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
but in node v22 it is not working
right now i am using node 20 for rollup thanks to nvm(node version manager). i am expecting to know if there is way to import .json files in node v22
thank you for your time.
i was configuring a rollup.config.mjs file and this is how i used to import json files
import packageJson from "./package.json" assert { type: "json" };
as far i have tested it works in node 20 without any errors but a warning of
(node:34471) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
but in node v22 it is not working
right now i am using node 20 for rollup thanks to nvm(node version manager). i am expecting to know if there is way to import .json files in node v22
thank you for your time.
Share Improve this question asked Jul 17, 2024 at 12:47 MUHAMMAD AsimMUHAMMAD Asim 1041 silver badge8 bronze badges 2-
2
try ->
with: { type: 'json' }
,` assert has been dropped, more info -> github./nodejs/node/issues/51622 – Keith Commented Jul 17, 2024 at 13:01 - 1 yup with keyword worked and i could rollup event without @rollup/plugin-json thanks alot – MUHAMMAD Asim Commented Jul 18, 2024 at 10:16
1 Answer
Reset to default 7As mentionned in @keith ment, you should do this since node22:
import packageJson from "./package.json" with { type: "json" };
or for dynamic import:
const { default } = await import('./file.json', {with: {type: 'json' }});