Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
requestforcriticism opened this issue Feb 29, 2024 · 3 comments

Comments

@requestforcriticism
Copy link

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
Copy link

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
Copy link

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
Copy link

s-light commented Oct 22, 2024

@AaronConlon i think you run into #143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants