jonschlinkert / gray-matter

Smarter YAML front matter parser, used by metalsmith, Gatsby, Netlify, Assemble, mapbox-gl, phenomic, vuejs vitepress, TinaCMS, Shopify Polaris, Ant Design, Astro, hashicorp, garden, slidev, saber, sourcegraph, and many others. Simple to use, and battle tested. Parses YAML by default but can also parse JSON Front Matter, Coffee Front Matter, TOML Front Matter, and has support for custom parsers. Please follow gray-matter's author: https://github.com/jonschlinkert

Home Page:https://github.com/jonschlinkert

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: gray_matter__WEBPACK_IMPORTED_MODULE_4__ is not a function

joeynimu opened this issue · comments

Hi there,

I am trying to use this module and, I am getting the below error;

TypeError: gray_matter__WEBPACK_IMPORTED_MODULE_4__ is not a function
// code
import * as matter from "gray-matter";

export async function getAllFilesFrontMatter(type) {
  const files = readdirSync(join(process.cwd(), "data", type));
  const posts = files.map((file) => {
    const fileContents = readFileSync(
      join(process.cwd(), "data", type, file),
      "utf8"
    );
    const { data } = matter(file); <--- throws an error
  });
  return posts;
}

What could be the issue here? I am using this function in a nextjs project, not sure if the issue is to do with webpack 5

I'm seeing the same issue after upgrading my npm packages. Did you find the solution?