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"
*/
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, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17260205.html
未经授权禁止转载,违者必究!
标签:
JSON
, import assert
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!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