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

grey-matter does not import as a function when using import statements #171

Open requestforcriticism opened 9 months ago

requestforcriticism commented 9 months ago

Getting an error when trying to run the following hello world example, I get an error where the matter export is not a function.

Offending code:

import * as matter from 'gray-matter';
console.log(matter('---\ntitle: Front Matter\n---\nThis is content.'));

Resulting error:

TypeError: matter is not a function
    at file:///C:/path/to/index.js:13:13
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

When I edit the export line in grey-matter/index.js in node modules to display:

module.exports = {matter};

I can then import and run the marked package like this just fine:

import { matter } from 'gray-matter';
console.log(matter('---\ntitle: Front Matter\n---\nThis is content.'));

Are node packages with "type":"module" not supported or is this behavior a bug?

robotastronaut commented 7 months ago

You can also just do import { default as matter } from 'gray-matter' and it should resolve it. This package should definitely play nicer with modules.

AaronConlon commented 3 months ago

You can also just do import { default as matter } from 'gray-matter' and it should resolve it. This package should definitely play nicer with modules.

I have a error: Buffer is not defined

s-light commented 1 month ago

@AaronConlon i think you run into #143