How can i render serverside with done-ssr and done-ssr-middleware?

i tried to do thinks described in the readme of and

i called: node index.js and got the error:

Potentially unhandled rejection [1] ReferenceError: document is not defined
    at C:\wamp\www\ssr\node_modules\done-ssr\lib\index.js:94:18

my package.json:

  "name": "ssr-test",
  "version": "1.0.0",
  "dependencies": {
    "can": "^2.3.23",
    "done-ssr": "^0.13.2",
    "done-ssr-middleware": "^0.3.0",
    "express": "^4.13.4"
  "system": {
    "directories": {
      "lib": "src"
    "npmAlgorithm": "flat"

my index.js:

var express = require('express');
var middleware = require("done-ssr-middleware");

var app = express();

app.use('/', middleware({
	config: __dirname + '/package.json!npm',
	main: "ssr-test/foo"

app.listen(3000, function () {
	console.log('Example app listening on port 3000!');

foo.js is steals main:

module.exports = function(req, res){
	return 'Hello World!';

@matthewp you are the godfather of ssr, any thoughts why this is not working?

My guess is you need to do something to “res”

the error said document is not defined it is something wrong in done-ssr

Hey @pYr0x, the issue is that our virtual DOM only loads as a dependency of jQuery. Since you are not importing jQuery the vdom is not loading and you are getting that error. This is a bug, I’ve filed an issue here:

In the meantime here’s a Hello Word that works:

var $ = require('jquery');

module.exports = function(){
  $(document.body).append($('<div>').text('Hello world'));

thanks @matthewp.
but why i do need jquery?

importing vdom worked also…?!


module.exports = function(req, res){
	var h1 = document.createElement("h1");
	h1.innerHTML = "hallo welt";

Yeah you don’t really need jQuery, you just need vdom. What happens in a typical donejs app is you are depending on can which depends on jquery which we shimmed to depend on vdom. If you’re not using these things then vdom is never being imported and you get your error. Still working on making this possible, in the meantime either approach will likely work.

thank for that description.

do you know a other library that provide a vdom for nodejs?

Yes, jsdom is the best by far, but it currently doesn’t work in done-ssr. I can’t recall the reason, I think it is because we have a hard dependency on can/util/vdom/vdom and some things use that as the document.

yeah, i tried that (jsdom) it throw an error on done-ssr.
so can/util/vdom/vdom is a needed dependency for done-ssr.

thanks a lot…

It’s a needed dep for now, I consider it a bug though.