简体   繁体   English

无法使用Traceur加载模块-尝试通过XHR访问文件

[英]Cannot load modules with traceur - tries to access file via xhr

I am trying to use traceur. 我正在尝试使用Traceur。 When I want to load a module though, I get an error that it was unsuccessful. 但是,当我想加载模块时,会收到错误消息,提示它不成功。 My code is based on the example traceur provided in its documentation on modules. 我的代码基于其模块文档中提供的示例traceur。

Here is the main.html: 这是main.html:

<script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
<script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>
<script>
     System.traceurOptions = { experimental: true } 
</script>

<script type="module" src="ProfileView.js"></script>

And the loaded module: 和加载的模块:

// ProfileView.js
import {firstName, lastName, year} from './Profile.js';

function setHeader(element) {
  element.textContent = firstName + ' ' + lastName;
}
// rest of module

// Profile.js
export var firstName = 'David';
export var lastName = 'Belle';
export var year = 1973;

I get the following error in Chrome: 我在Chrome中收到以下错误:

XMLHttpRequest cannot load file:///C:/Code/Tests/Traceur/ProfileView.js. XMLHttpRequest无法加载文件:/// C:/Code/Tests/Traceur/ProfileView.js。 Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource. 跨源请求仅支持以下协议方案:http,数据,chrome,chrome扩展名,https,chrome-extension-resource。

WebPageTranscoder FAILED to load file:///C:/Code/Tests/Traceur/ProfileView.js WebPageTranscoder失败以加载文件:/// C:/Code/Tests/Traceur/ProfileView.js

Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/Code/Tests/Traceur/ProfileView.js'. 未捕获到的NetworkError:无法在'XMLHttpRequest'上执行'send':无法加载'file:/// C:/Code/Tests/Traceur/ProfileView.js'。

I know that you cant make xhr-requests via the file system but I have seen some tutorials in which the code is structured similarly to mine and it works there... 我知道您无法通过文件系统进行xhr请求,但我看过一些教程,其中的代码结构与我的相似,并且在那里工作。

What may I be doing wrong? 我可能做错了什么?

You cannot access the file system with xhr, you should open those pages over http by running a local webserver. 您无法使用xhr访问文件系统,应通过运行本地Web服务器通过http打开那些页面。 If you really want to enable file system access you can: http://www.chrome-allow-file-access-from-file.com/ 如果您确实要启用文件系统访问权限,则可以: http : //www.chrome-allow-file-access-from-file.com/

Ie you start chrome chrome.exe --allow-file-access-from-files 即您启动chrome chrome.exe --allow-file-access-from-files

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM