Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: window is not defined #485

Closed
cuiweiqiang opened this issue Mar 7, 2017 · 7 comments
Closed

ReferenceError: window is not defined #485

cuiweiqiang opened this issue Mar 7, 2017 · 7 comments

Comments

@cuiweiqiang
Copy link

cuiweiqiang commented Mar 7, 2017

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

@szaliszali
Copy link

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.

@tylerlong
Copy link
Collaborator

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

@jbmusso
Copy link

jbmusso commented Jan 7, 2019

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.

@Schachte
Copy link

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

@elgunhuseynli
Copy link

@tylerlong Still cannot use in NodeJS :(

@Schachte
Copy link

Schachte commented Jun 4, 2019

:(

@davibe
Copy link

davibe commented Jul 26, 2019

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

mgenereu pushed a commit to mgenereu/mermaid that referenced this issue Jun 25, 2022
Bumps [@sveltejs/kit](https://github.com/sveltejs/kit/tree/HEAD/packages/kit) from 1.0.0-next.192 to 1.0.0-next.194.
- [Release notes](https://github.com/sveltejs/kit/releases)
- [Changelog](https://github.com/sveltejs/kit/blob/master/packages/kit/CHANGELOG.md)
- [Commits](https://github.com/sveltejs/kit/commits/HEAD/packages/kit)

---
updated-dependencies:
- dependency-name: "@sveltejs/kit"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants