Answer the question
In order to leave comments, you need to log in
How to solve the problem with browser-based Babel?
Hello, there is a problem with connecting the latest version of the browser-based Babel standalone via unpkg CDN. The problem is this: when I try to connect Babel to a javascript file in VSCode , I get the following error:<script type="text/babel src="app.js">
Access to XMLHttpRequest at 'file:///work/.../app.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
GET file:///work/.../app.js net::ERR_FAILED
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script crossorigin src="https://unpkg.com/[email protected]/babel.min.js"></script>
<title>Document</title>
</head>
<body>
<script type="text/babel" src="app.js"></script>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Babel standalone latest version via unpkg CDN
So, as promised, here is an example of a working code, hello world of
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js" crossorigin></script>
<body>
<div id="hello"></div>
<script src="script.js" type="text/babel"></script>
</body>
</html>
const hello = (
<div>hello world</div>
)
const domContainer = document.querySelector('#hello');
ReactDOM.render(hello, domContainer);
babel for react probably can't be used through a script, you need to embed it in the assembly and add preset-react there
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question