javascript - How do you correctly import react into a node-webkit app? -
i'm trying create node-webkit app, , want use react.js framework. after trying react , creating components, tried use follows in node-webkit app:
'use strict'; require('react');
whenever open node-webkit app, includes above script @ end of body error:
referenceerror: document not defined @ object.<anonymous> (c:\users\rtol\dropbox\code\node- webkit\wallpapermanager3.0\node_modules\react\lib\csspropertyoperations.js:31:7) ....
am doing wrong? documentation i've found indicates correct way include react when using node. have npm installed react, according package.json version 0.13.2.
for instance react-nodewebkit starter kit has it's index.jsx follows.
var react = require('react'); var helloworld = require('./components/helloworld.jsx'); react.render(<helloworld />, document.getelementbyid('content'));
so can't figure out why doesn't work.
nw.js (which node-webkit renamed to) has 2 contexts in scripts can executed - browser or node. see determining context of script on nw.js wiki
note starter project linked bundles javascript using browserify , loads via <script>
tag. result code being run in browser context, in document
available.
if you're using require()
directly import code, that's running in node context, in document
not available. if you'd got further you'd have hit issues using react if imported require()
, detects whether or not it's being executed in browser context , behaves accordingly.
Comments
Post a Comment