D
D
Denis11112018-07-31 14:54:25
JavaScript
Denis1111, 2018-07-31 14:54:25

I'm trying to include babel for react in html. Writes File to load file:///D:/Programmes/Projects/Project1/scripts/script.js?

Writes File to load file:///D:/Programmes/Projects/Project1/scripts/script.js: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
What's the matter?
HTML:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Infinity</title>
    <link rel="shortcut icon" href="images/CD.ico" type="html/x-icon" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <script src="https://code.jquery.com/jquery-3.2.1.js"></script>
    <script src="scripts/react.js"></script>
    <script src="scripts/react-dom.js"></script>
    <script src="scripts/browser.min.js"></script>
    <script type="text/babel" src="scripts/script.js" defer></script>
</head>

<body>
    <div id="example "></div>
</body>

</html>

JS:
ReactDOM.render( 
  <h1>Hello, world!</h1>,
  document.getElementById('example');
));

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Spirin, 2018-07-31
@Denis1111

I think create-react-app or codesandbox would be your best bet for now .
The problem itself is that you are opening the document in the browser, and not getting it from the server.

N
Nick, 2018-07-31
@DragonSpirit

Try to open the file not directly from the local machine, but raise a simple static server (SimpleHTTPServer, node-static)

M
Maxim, 2018-07-31
@maxfarseer

You can see how to work with react inside index.html here: " include react as a script "

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question