javascript - Invariant Violation: Invalid tag: 'use strict'; -


while transpiling following index.js file, error:

invariant violation: invalid tag: 'use strict';

i using babel-core, react, react-dom.

my index.js file:

import react 'react' import { render } 'react-dom' import { router, route, browserhistory, indexroute } 'react-router' import app './components/app' import home './components/home' import funddetail './components/funddetail'  render((   <router history={browserhistory}>     <route path="/" component={app}>       <indexroute component={home}/>       <route path="/fund/:id" component={funddetail}/>     </route>   </router> ), document.getelementbyid('content')) 

my .babaelrc file:

{   "presets": ["es2015"],   "plugins": ["transform-strict-mode", "transform-react-jsx"] } 

server code:

    var react = require("react");     var reactdom = require("react-dom/server");     var babel = require('babel-core');     var component;     babel.transformfile("./assets/js/index.js", {}, function (err, result) {       if(err) {         sails.log.error(err)       } else {         component = react.createfactory(result.code);         var comp = component();         res.send(reactdom.rendertostring(comp));       }     }); 

what should do?

i'm guessing transform-react-jsx isn't thing need, why not use preset? can see there more transform:

npm babel-preset-react --save 

and add .babelrc:

"presets": ["es2015", "react"] 

and remove transform.

also try babel-core/register on server.

i'm not sure you're doing babel.transformfile? like:

server.get('*', require('./router')); 

where file exporting function uses react-router's match. haven't seen approach before of requiring index.js file (which isn't exporting anything) doing react render?


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -