Mermaid: ReferenceError: window is not defined

Created on 7 Mar 2017  路  7Comments  路  Source: mermaid-js/mermaid

In Node REPL when I type const mermaid = require('mermaid'); it tell me

ReferenceError:
window is not defined
at new Log (/[my project]/node_modules/mermaid/src/logger.js:87:18)
at Object. (/[my project]/node_modules/mermaid/src/mermaid.js:8:11)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at repl:1:17

And I try to install it with these ways:
npm install mermaid
npm install git+https://github.com/knsv/mermaid.git
but it still not work.

My Node version is v7.7.1,
and npm version is 4.1.2

Most helpful comment

Unsure if this is expected, but it looks like mermaid v8.0.0 cannot be used in Node.js (window is not defined error). Using mermaid v7.1.0 seems to work fine though.

All 7 comments

You should not require('mermaid') in a node environment. It requires a web browser (or a headless browser like PhantomJS).

Depending on your goal, you may or may not succeed by using its subcomponents as a library (see https://knsv.github.io/mermaid/#development11).
Alternatively, you can use the bundled CLI tool as an external process.

Version 7.1.0 allows you to use mermaid in node directly.(but you still need a browser environment in order to render).

Example: https://github.com/mermaidjs/mermaid-live-editor/blob/fe51c26ecf77027fd882af0c6034b1c99c555601/src/components/Preview.js#L6

Unsure if this is expected, but it looks like mermaid v8.0.0 cannot be used in Node.js (window is not defined error). Using mermaid v7.1.0 seems to work fine though.

@tylerlong Why did this lose support in the v8 release?

@tylerlong Still cannot use in NodeJS :(

:(

I wanted to use mermaid JS while transpiling markdown to html+js+css. During transpilation I do not have a browser environment available (normally).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CyborgMaster picture CyborgMaster  路  14Comments

Remo picture Remo  路  27Comments

chetanvsharma picture chetanvsharma  路  17Comments

knsv picture knsv  路  20Comments

Anachron picture Anachron  路  16Comments