无网络HTML,如果index.html在本地提供,可以使用babel-standalone吗?(无网络服务器)...

金伟
2023-12-01

在我开始问题之前,这是我已经知道的避免相同答案的信息。

TL; DR: 我已经知道我可以使用网络服务器并将index.html用作http:// localhost:8081 /

index.html,它将可以正常工作。

现在查看问题详细信息:

我创建了一个最小的react-js应用程序,在index.html文件中引用babel-standalone,如下所示:

Minimal

并且index.js的内容是:

class YoSupComponent extends React.Component {

constructor () {

super();

this.state = {

message: 'whatever...'

};

}

componentDidMount() {

console.log('YoSupComponent.componentDidMount');

}

render () {

return (

Yo ! Dude or Dudette... sup ?

);

}

}

const props = {}; //none for now...

ReactDOM.render(

, document.getElementById('divRootComponent'))

当我尝试通过file:///path/to/index.html访问浏览器中的index.html文件时,错误是:

通过CORS策略已阻止从源“ null”访问“ file:///

D:/path/to/index.js”处的XMLHttpRequest:仅协议方案支持跨源请求:http,数据,chrome,chrome

-扩展名,https。@ babel.min.js:24

因此,认为问题与远程引用文件的脚本标签有关,我在本地下载react和babel,并使引用成为本地文件;然后我再次访问file:///path/to/index.html。

还是会得到同样的错误!这是怎么回事?a)当babel.js文件现在位于本地时,为什么babel甚至甚至使用XMLHttpRequest(根据错误消息)?b)为什么没有这样的反应文件消息?

 类似资料: