xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

JSON & import assertions All In One

JSON & import assertions All In One

error

// const packageInfo = require("./package.json");

import * as pkg from "./package.json";

console.log(`pkg `, pkg);


/*

TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "file:///Users/xgqfrms-mm/Documents/github/app-node-env/package.json" needs an import assertion of type "json"

*/


image

solution

// const packageInfo = require("./package.json");

import * as pkg from "./package.json" assert { type: "json" };
console.log(`pkg `, pkg);

/*

(node:33503) ExperimentalWarning: Importing JSON modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

*/

import assertions

https://v8.dev/features/import-assertions

https://github.com/tc39/proposal-import-attributes

blog

https://2ality.com/2021/01/import-assertions.html

https://2ality.com/2021/06/json-modules.html

refs

https://www.cnblogs.com/xgqfrms/p/14927874.html

bug

https://github.com/whatwg/html/issues/7233



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(500)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-03-27 Apple 开发者账号 All In One
2022-03-27 Stanford CS193p All In One
2022-03-27 Harvard University CS50 2022 All In One
2022-03-27 table 组件性能优化 All In One
2022-03-27 vite preview not work All In One
2021-03-27 linux bash shell auto read write template
2020-03-27 ES-Next classes static properties
点击右上角即可分享
微信分享提示