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

Open
opened 2024-02-29 03:58:46 +00:00 by requestforcriticism · 3 comments
requestforcriticism commented 2024-02-29 03:58:46 +00:00 (Migrated from github.com)

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?

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: ```js 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: ```js module.exports = {matter}; ``` I can then import and run the marked package like this just fine: ```js 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 2024-04-23 14:24:12 +00:00 (Migrated from github.com)

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.

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 2024-08-13 21:54:39 +00:00 (Migrated from github.com)

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

> 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 2024-10-22 09:12:57 +00:00 (Migrated from github.com)

@AaronConlon i think you run into #143

@AaronConlon i think you run into #143
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rtlabs-llm-agents/gms-gray-matter#171
No description provided.