Gruntfuggly / mermaid-export

A vscode extension to wrap mermaid.cli in order to export mermaid diagrams to image files
15 stars 4 forks source link

can't export, error - Expecting 'NEWLINE', 'SPACE', 'GRAPH', got 'PUNCTUATION' #6

Open rpinku opened 5 years ago

rpinku commented 5 years ago

When trying to export got this error, even when trying to simplify significantly the graph. command:c:\Users\prami.vscode\extensions\gruntfuggly.mermaid-export-0.0.7/node_modules/.bin/mmdc -t default -i "c:\Users\prami\OneDrive - Dalet Digital Media Systems\R&D\BI\Product Tree\productTree.md" -o "c:\Users\prami\OneDrive - Dalet Digital Media Systems\R&D\BI\Product Tree\productTree.png" (node:31100) UnhandledPromiseRejectionWarning: Error: Evaluation failed: Error: Parse error on line 1:


^
Expecting 'NEWLINE', 'SPACE', 'GRAPH', got 'PUNCTUATION'
    at Yt.parseError (file:///C:/Users/prami/.vscode/extensions/gruntfuggly.mermaid-export-0.0.7/node_modules/mermaid.cli/mermaid.min.js:1:486512)
    at Yt.parse (file:///C:/Users/prami/.vscode/extensions/gruntfuggly.mermaid-export-0.0.7/node_modules/mermaid.cli/mermaid.min.js:1:487678)
    at Object.e.getClasses (file:///C:/Users/prami/.vscode/extensions/gruntfuggly.mermaid-export-0.0.7/node_modules/mermaid.cli/mermaid.min.js:1:749437)
    at Object.render (file:///C:/Users/prami/.vscode/extensions/gruntfuggly.mermaid-export-0.0.7/node_modules/mermaid.cli/mermaid.min.js:1:759998)
    at s (file:///C:/Users/prami/.vscode/extensions/gruntfuggly.mermaid-export-0.0.7/node_modules/mermaid.cli/mermaid.min.js:8:233)
    at Object.init (file:///C:/Users/prami/.vscode/extensions/gruntfuggly.mermaid-export-0.0.7/node_modules/mermaid.cli/mermaid.min.js:8:318)
    at __puppeteer_evaluation_script__:17:20
    at ExecutionContext._evaluateInternal (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\ExecutionContext.js:122:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async ExecutionContext.evaluate (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\ExecutionContext.js:48:12)
    at async ElementHandle.evaluate (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\JSHandle.js:55:12)
    at async ElementHandle.$eval (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\JSHandle.js:478:20)
  -- ASYNC --
    at ExecutionContext.<anonymous> (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\helper.js:111:15)
    at ElementHandle.evaluate (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\JSHandle.js:55:42)
    at ElementHandle.<anonymous> (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\helper.js:112:23)
    at ElementHandle.$eval (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\JSHandle.js:478:40)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
  -- ASYNC --
    at ElementHandle.<anonymous> (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\helper.js:111:15)
    at DOMWorld.$eval (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\DOMWorld.js:156:21)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
  -- ASYNC --
    at Frame.<anonymous> (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\helper.js:111:15)
    at Page.$eval (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\Page.js:347:29)
    at Page.<anonymous> (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\puppeteer\lib\helper.js:112:23)
    at c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\mermaid.cli\index.bundle.js:83:14
    at Generator.next (<anonymous>)
    at step (c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\mermaid.cli\index.bundle.js:4:191)
    at c:\Users\prami\.vscode\extensions\gruntfuggly.mermaid-export-0.0.7\node_modules\mermaid.cli\index.bundle.js:4:361
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

(node:31100) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:31100) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Gruntfuggly commented 5 years ago

Looks like you have an error in the source document and the extension isn't handling failures properly. Please can you post your diagram source so I can recreate it.

rpinku commented 5 years ago

I found the cause, it happens because I use the markdown preview extension for which I need to put the mermaid code inside

.........

to resolve this I now add %% before these two lines when I want to export

Gruntfuggly commented 5 years ago

Please could you post an example? It would be good to add to the README.md.

rpinku commented 5 years ago

This will show well when using the VSC plaugin Markdown Preview mermaid Support

graph TB
    A-->B
    A-->C
    B-->D

But if you wish to export it to an image you need to add %% otherwise the export will fail to parse %%mermaid graph TB A-->B A-->C B-->D %%

Gruntfuggly commented 5 years ago

I'm slightly confused - is the mermaid snippet embedded in a markdown document?

cmal commented 1 year ago

similiar problem:

 (node:8104) UnhandledPromiseRejectionWarning: Error: Evaluation failed: Error: Parse error on line 1:

^
Expecting 'NEWLINE', 'SPACE', 'GRAPH', got 'EOF'
    at Yt.parseError (file:///Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/mermaid.min.js:1:486512)
    at Yt.parse (file:///Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/mermaid.min.js:1:487678)
    at Object.e.getClasses (file:///Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/mermaid.min.js:1:749437)
    at Object.render (file:///Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/mermaid.min.js:1:759998)
    at s (file:///Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/mermaid.min.js:8:233)
    at Object.init (file:///Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/mermaid.min.js:8:318)
    at __puppeteer_evaluation_script__:17:20
    at ExecutionContext._evaluateInternal (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/ExecutionContext.js:122:13)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async ExecutionContext.evaluate (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/ExecutionContext.js:48:12)
    at async ElementHandle.evaluate (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/JSHandle.js:55:12)
    at async ElementHandle.$eval (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/JSHandle.js:478:20)
  -- ASYNC --
    at ExecutionContext.<anonymous> (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/helper.js:111:15)
    at ElementHandle.evaluate (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/JSHandle.js:55:42)
    at ElementHandle.<anonymous> (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/helper.js:112:23)
    at ElementHandle.$eval (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/JSHandle.js:478:40)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
  -- ASYNC --
    at ElementHandle.<anonymous> (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/helper.js:111:15)
    at DOMWorld.$eval (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/DOMWorld.js:156:21)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
  -- ASYNC --
    at Frame.<anonymous> (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/helper.js:111:15)
    at Page.$eval (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/Page.js:347:29)
    at Page.<anonymous> (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/helper.js:112:23)
    at /Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/index.bundle.js:83:14
    at Generator.next (<anonymous>)
    at step (/Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/index.bundle.js:4:191)
    at /Users/yuzhao/.nvm/versions/node/v14.19.3/lib/node_modules/mermaid.cli/index.bundle.js:4:361
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:8104) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:8104) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
^C%

same code can be evaluated in mermaid live editor

code here :

flowchart
      A(A) -- X --> B
      B -- Y --> C(C)
      B -- Z --> D(D)
zavvio commented 1 year ago

Note: Below, I'm using the character ' to represent ` due to formatting issue on github.

I had the same issue when I tried to export a mermaid code embedded in a markdown .md file containing the following content.

Filename: example.md

'''mermaid
graph TD;
    A((0));
    B((1));
    A-->B;
'''

The "fix" I found is, do not give your filename a .md extension and do not embed it in the

'''mermaid '''

block; i.e. just use a plain file without or any file extension other than .md, and use raw mermaid code, e.g.

Filename: example.txt

graph TD;
    A((0));
    B((1));
    A-->B;

The export should now be successful.

p.s. I also had to install Node.js first and execute

npm install ~/.vscode/extensions/gruntfuggly.mermaid-export-0.0.8/node_modules/mermaid.cli node ~/.vscode/extensions/gruntfuggly.mermaid-export-0.0.8/node_modules/puppeteer/install.js