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
https://github.com/jonschlinkert
MIT License
3.97k stars 138 forks source link

Library is not compatible with Edge runtime #175

Open bmamouri opened 1 month ago

bmamouri commented 1 month ago

I am trying to use gray-matter in Next.js edge runtime. But it seems that the library is not compatible with edge runtime. I am getting the following error:

Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime 
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation

The error was caused by importing 'gray-matter/index.js' in './lib/api.ts'.

I get the error even when disabling eval:

  const {data, content} = matter(fileContents, {eval: false})

Is there any way to make this library edge friendly? Does anybody know any alternative that can be used with edge?

s-light commented 1 month ago

for me it is only a warning currently with my quasar / vue / vite setup:

Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification Cannot call a namespace ('matter') Cannot call a namespace ('matter')

but this warning also mentioned if i set the eval:false option..