2

I am trying to learn React. I am trying to display the string Hello World but get the following error in my browser:

Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: C:\react\react-app\src\index.js: Missing semicolon. (1:6)

And I get these errors in my Editor: 1)'import ... =' can only be used in TypeScript files. 2)'=' expected. 3)';' expected.

My code is as follows:

import React from "react";
import ReactDom form "react-dom";

const element = <h1>Hello World</h1>;
ReactDom.render(element, document.getElementById('root'));

I would appreciate any help.

1
  • 2
    There's a typo in import of react-dom. It should be from instead of form. Commented Jun 10, 2022 at 13:30

2 Answers 2

1

See neeraj tk's comment = correct answer

I typed from instead of form. When I fixed this the code worked.

Sign up to request clarification or add additional context in comments.

Comments

0
ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
  document.getElementById('root')
);

index.tsx

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);
root.render(
  <React.StrictMode>
    <react-app />
  </React.StrictMode>
);
reportWebVitals();

2 Comments

thank you, I tried your code and then the first two errors went away but I still get the following error: ',' expected. ts (1005) [Ln5,Col5] The code is used was: ReactDOM.render( <React.StrictMode> <react-app /> </React.StrictMode> document.getElementById('root') );
if use ts , you can try i edited

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.