javascript - How to import json files in node v22 - Stack Overflow

i was configuring a rollup.config.mjs file andthis is how i used to import json filesimport packageJs

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
Add a ment  | 

1 Answer 1

Reset to default 7

As 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' }});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745037686a4607617.html

相关推荐

  • javascript - How to import json files in node v22 - Stack Overflow

    i was configuring a rollup.config.mjs file andthis is how i used to import json filesimport packageJs

    9小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信