javascript - React renderToStaticMarkup and "Invariant Violation: Invalid tag" error -
i keep getting "invariant violation: invalid tag" errors when try convert jsx file js , generate html saving static html file. here test.js file:
var fs = require("fs"); var babel = require("babel-core"); var react = require("react"); var reactdomserver = require("react-dom/server"); fs.readfile('./template.js', function(err, data) { var template = babel.transform(data, { "presets": ["es2015", "react"], "plugins": ["transform-es2015-modules-umd"] }); template = react.createelement(template.code); console.log(reactdomserver.rendertostaticmarkup(template)); });
here template.js file:
const react = require('react'); module.exports = react.createclass({ render: function() { return <div>hello {this.props.name}</div>; } });
here console dump:
bills-mbp:white-label bshack$ node test.js /users/bshack/sites/white-label/node_modules/react/node_modules/fbjs/lib/invariant.js:45 throw error; ^ invariant violation: invalid tag: (function (global, factory) { if (typeof define === "function" && define.amd) { define(['module', 'react'], factory); } else if (typeof exports !== "undefined") { factory(module, require('react')); } else { var mod = { exports: {} }; factory(mod, global.react); global.unknown = mod.exports; } })(this, function (module, react) { 'use strict'; module.exports = react.createclass({ displayname: 'exports', render: function render() { return react.createelement( 'div', null, 'hello ', this.props.name ); } }); }); @ invariant (/users/bshack/sites/white-label/node_modules/react/node_modules/fbjs/lib/invariant.js:38:15) @ validatedangeroustag (/users/bshack/sites/white-label/node_modules/react/lib/reactdomcomponent.js:299:74) @ new reactdomcomponent (/users/bshack/sites/white-label/node_modules/react/lib/reactdomcomponent.js:326:3) @ object.createinternalcomponent (/users/bshack/sites/white-label/node_modules/react/lib/reactnativecomponent.js:68:10) @ instantiatereactcomponent (/users/bshack/sites/white-label/node_modules/react/lib/instantiatereactcomponent.js:70:39) @ /users/bshack/sites/white-label/node_modules/react/lib/reactserverrendering.js:37:31 @ reactserverrenderingtransaction.mixin.perform (/users/bshack/sites/white-label/node_modules/react/lib/transaction.js:136:20) @ rendertostringimpl (/users/bshack/sites/white-label/node_modules/react/lib/reactserverrendering.js:36:24) @ object.rendertostaticmarkup (/users/bshack/sites/white-label/node_modules/react/lib/reactserverrendering.js:59:10) @ /users/bshack/sites/white-label/test.js:11:32
it keeps giving me same error when start delete lines complains about. ideas?
Comments
Post a Comment