node:internal/errors:464
9:07:48 PM: ErrorCaptureStackTrace(err);
9:07:48 PM: ^
9:07:48 PM: TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "file:///opt/build/repo/.contentlayer/generated/Blog/blog__BLANK.mdx.json" needs an import assertion of type
但是我有 --experimental-json-modules 作为构建选项
当我删除它有效的有问题的 json 文件时,我真的很困惑,奇怪的是,我有一份时事通讯,它的工作原理与 .json 结尾非常相似,而且它有效。
导入后您需要
assert
:
// "(node:3933) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language.
// Avoid relying on their current behavior and syntax as those might change in a future version of Node.js."
// The proposed official syntax is `with` instead of `assert`. https://github.com/tc39/proposal-import-attributes
import json_object from "./blog__BLANK.mdx.json" assert { type: "json" };
console.log("typeof json_object =", typeof json_object); // typeof json_object = object