@@ -2,7 +2,7 @@ import { unified } from 'unified'
2
2
import remarkParse from 'remark-parse'
3
3
import remark2rehype from 'remark-rehype'
4
4
import { parseFrontMatter } from 'remark-mdc'
5
- import type { Options as VFileOptions } from 'vfile'
5
+ import type { VFile , Options as VFileOptions } from 'vfile'
6
6
import { defu } from 'defu'
7
7
import type { MdcConfig , MDCData , MDCElement , MDCParseOptions , MDCParserResult , MDCRoot , Toc } from '@nuxtjs/mdc'
8
8
import { nodeTextContent } from '../utils/node'
@@ -104,9 +104,20 @@ export const createMarkdownParser = async (inlineOptions: MDCParseOptions = {})
104
104
const { content, data : frontmatter } = await parseFrontMatter ( md )
105
105
106
106
// Start processing stream
107
- const processedFile = await processor . process ( { cwd : typeof process . cwd === 'function' ? process . cwd ( ) : '/tmp' , ...fileOptions , value : content , data : frontmatter } )
108
-
109
- const result = processedFile . result as { body : MDCRoot , excerpt : MDCRoot | undefined }
107
+ const cwd = typeof process !== 'undefined' && typeof process . cwd === 'function' ? process . cwd ( ) : '/tmp'
108
+ const processedFile : VFile | undefined = await new Promise ( ( resolve , reject ) => {
109
+ // There is an issue with bundler optimizer which causes undefined error
110
+ // When using processor.process as a promise. Use callback instead to avoid this issue
111
+ processor . process ( { cwd, ...fileOptions , value : content , data : frontmatter } , ( err , file ) => {
112
+ if ( err ) {
113
+ reject ( err )
114
+ } else {
115
+ resolve ( file )
116
+ }
117
+ } )
118
+ } )
119
+
120
+ const result = processedFile ?. result as { body : MDCRoot , excerpt : MDCRoot | undefined }
110
121
111
122
// Update data with processor data
112
123
const data = Object . assign (
0 commit comments