JSON & import assertions All In One

发布时间 2023-03-27 03:06:11作者: xgqfrms

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"

*/


// 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)

*/

(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs



©xgqfrms 2012-2021

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

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