React & asp.net - Importing react-bootstrap exception

Viewed 250

I did npm install on the folder with the react content. I'm not using webpack or bundler I pretty much went off this tutorial for setup, because I only need React as components https://reactjs.net/getting-started/aspnet.html and get this error

  • $exception {"Error while loading \"~/Scripts/react/Components/Progression/ProgressionTable.js\": SyntaxError: Unexpected identifier\r\n at ProgressionTable.js:14:8 -> import Modal from 'react-bootstrap';"} React.Exceptions.ReactScriptLoadException

so essentially it's complaining about the 'import' statement and it always does this for any import. What do I do?

1 Answers

In short import is not supported JS by the browsers so you need to use webpack/babel-loader to turn those import statements into JS that still works.

You would have to use a browser based loader like Require.JS to get your existing code to work here, but your better off having a look at enabling module import loading via Webpack/Babel.

To sum it up, having the right tooling in place will prevent import statements in your compile JS code that the browser has no idea how to handle.

Related