DEV Community

Discussion on: Setting up a React Environment for ASP.NET MVC

Collapse
 
webatxcent profile image
Bill Butler

Hi, I tried out your process using VS2019, step by step and got the following error. Was hoping you might nudge me in the right direction :). [I am a relative newbie with npm]

ERROR in ./Scripts/Home/react/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: d:\Docs\Scratch\ReactTest\Web\Scripts\Home\react\index.js: Unexpected token (5:4)

  3 |
  4 | const App = () => (
> 5 |     <>
    |     ^
  6 |         <h1>React in ASP.NET MVC!</h1>
  7 |         <div>Hello React World</div>
  8 |     </>
    at Parser.raise (d:\Docs\Scratch\ReactTest\Web\node_modules\@babel\parser\lib\index.js:6400:17)
...
Collapse
 
dance2die profile image
Sung M. Kim • Edited

Hi Bill.

I am sorry it's because the code snippet is out of sync from the instruction. You might want to use React.Fragment instead of <>...</> because it's a syntatic sugar (you'd need to set up plugin-transform-react-jsx for that syntax to work, which is not set up in this article.)

As a workaround, you can use React.Fragment directly as shown below (I've also updated the gist to reflect the change).

import React from 'react';
import { render } from 'react-dom';

const App = () => (
    <React.Fragment>
        <h1>React in ASP.NET MVC!</h1>
        <div>Hello React World</div>
    </React.Fragment>
);

render(<App />, document.getElementById('app'));
Collapse
 
webatxcent profile image
Bill Butler

Thanks so much for the quick reply.
That didn't change the outcome. Same error unexpected token.

I did note that the first line in the index.js file

import React from 'react';

was reporting an Intellisense error: "(js) cannot use imports, exports, or module augmentations when '--module' is 'none'"
Could this be a contributing factor.