vfile-matter is a utility package for the vfile ecosystem, designed to parse YAML front matter found at the beginning of a virtual file. It's currently stable at version 5.0.1, with minor updates and patch releases occurring as needed, and major versions released periodically to align with ecosystem updates and Node.js LTS cycles. This package populates the parsed data into `file.data.matter` and can optionally strip the front matter content from the file's `value`. A key differentiator is its tight integration with `vfile`, making it suitable for direct file manipulation when not using a higher-level parsing system like remark. Since version 4.0.0, it uses the more modern `yaml` package for parsing, replacing `js-yaml`. It's important to note that this package is distinct from `remark-frontmatter`, which should be used when processing Markdown with `remark` rather than directly manipulating `vfile` objects.
npm install vfile-matterVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing YAML front matter from a virtual file and stripping it from the content using `vfile-matter`.
Upgrade your Node.js environment to version 16 or newer.
Access the modified file directly from the variable you passed to `matter`, e.g., `const file = await read(...); matter(file); console.log(file.data.matter);`
Migrate your project to use ECMAScript Modules (`import`/`export`) or stick to `vfile-matter@2.x` if CJS is strictly required.
Review `YamlOptions` for any parser-specific configurations if you encounter unexpected behavior after upgrading from v3.x.
For `remark` pipelines, use `import remarkFrontmatter from 'remark-frontmatter'` and add it to your `unified().use(...)` chain.
Only use `strip: true` if you are certain no downstream processes depend on the original positional information. Otherwise, manage the content without stripping the front matter.
Change `const { matter } = require('vfile-matter')` to `import { matter } from 'vfile-matter'` and ensure your project uses ES modules (e.g., `"type": "module"` in package.json or `.mjs` file extension).Ensure you are using a named import: `import { matter } from 'vfile-matter'`. Also verify that the `file` object passed to `matter` is a valid `VFile` instance.First, ensure `npm install vfile-matter` is run. If it persists, check your Node.js version (must be 16+ for v5.0.0+). If using specific module resolution tools, check their configuration.