简体   繁体   中英

Server-side rendering of React-Bootstrap, unexpected token error

I am trying to re-write the React code to use mostly server-side rendering and I faced an issue with React-Bootstrap . Switching from import Grid from 'react-bootstrap/lib/Grid'; to var Grid = require('react-bootstrap/lib/Grid'); gives an error in render method:

在此处输入图片说明

How should the importing of the React-Bootstrap components should be done then? Is it possible at all for React-Bootstrap ? Any suggestions would be greatly appreciated.

I think this particular issue is solved. The error is gone after running npm install babel-register , npm install babel-preset-react and adding the following code at the top that tries to create DOM element out of ScatterChart

require('babel-register')({
    presets: ['react']
});

I found it here: https://medium.com/@remarkablemark/server-side-rendering-with-react-46715f501651

Very important is to define the presets above all of the import statements, at the very top of the file, otherwise the error is not going away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM