About using window and document in node-jsx and react-engine

38 views Asked by At

I want to use .pug and .jsx as express view engine.
I tried it with other modules like @react-ssr/express, but they didn't work.
(It seems that my project is based on a open source project that lastly updated a few years ago)
So, I'm using node-jsx and react-engine now, but these modules wouldn't let me use window and document.
(Like this screenshot)
I already tried many solutions through googling like the code below.

const React = require("react");

...

const Index = (props) => {
  if (typeof window !== 'undefined') {
    // code with document and window
  }
}

module.exports = Index;

But blank page was rendered.
I think these modules just render and run my jsx file without any converting to javascript.
Is there no way to use window and document with node-jsx and react-engine?
(or please recommend me other modules)

server.js

require("node-jsx").install({ extension: '.jsx', harmony: true });

const renderer = require("react-engine");
const Engine = renderer.server.create();

...

app.set('views', __dirname + "/views");
app.engine('jsx', Engine);
app.set('view engine', "pug");
app.set('view engine', "jsx");

index.jsx

const React = require("react");

...

const Index = (props) => {
  // code with document and window
}

module.exports = Index;
0

There are 0 answers