首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >StealJS错误:协议方案不支持跨域请求

StealJS错误:协议方案不支持跨域请求
EN

Stack Overflow用户
提问于 2015-06-27 01:54:13
回答 2查看 237关注 0票数 0

我遇到了这样的错误:

代码语言:javascript
复制
XMLHttpRequest cannot load file:///Users/mshin/workspace/spirent/trinity/trinity-link/public/node_modules/can/view/stache/system.js. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

home.js:

代码语言:javascript
复制
import can from 'can';
import template from './home.stache!';

export default can.Component.extend({
  tag: 'home',
  template: template
});

Gruntfile中的构建配置:

代码语言:javascript
复制
"steal-build": {
  default: {
    options: {
      system: {
        config: "package.json!npm",
        bundlesPath: "production"
      },
      buildOptions: {
        minify: true,
        sourceMaps: true
      }
    }
  }
}

我不知道为什么在生产模式下会收到这个错误消息。在开发环境中,它工作得很好。此外,它在测试环境中也很好用。我正在对被测试者运行QUnit测试。

home_test.js:

代码语言:javascript
复制
import QUnit from 'steal-qunit';
import ViewModel from 'components/home/home';
import can from 'can';
import stache from 'can/view/stache/';
import $ from 'jquery';

var template = can.stache('<home></home>'),
    $component;

QUnit.module('home component', {
  setup: function() {
    $('#trinity-js-tests').html(template());
    $component = $('#trinity-js-tests').find('home');
  }
});

QUnit.test('title tag', function() {
  QUnit.ok($component.find('h1'), 'Page shows title with <h1> tag');
});

QUnit.test('title content', function() {
  QUnit.strictEqual($component.find('h1').text(), 'This is homepage.', 'Title is "This is homepage."');
});

但是,如果我将home.js改为如下所示:

代码语言:javascript
复制
import can from 'can';

export default can.Component.extend({
  tag: 'home',
  template: can.view('components/home/home.stache)
});

它在生产和开发环境中运行良好,但在测试中最后一个测试用例失败。

代码语言:javascript
复制
1) QUnit "public/tests/test.html" on PhantomJS 1.9.8 / Mac OS X 0.0.0: <a href="http://localhost:3996/public/tests/test.html?__token=k8l88m"></a>  home component title content Title is "This is homepage.":
     Error: Expected This is homepage. but was
      at http://localhost:3996/public/tests/test.html?__token=k8l88m:1340
      at http://localhost:3996/public/tests/test.html?__token=k8l88m:1907
      at :33
      at http://localhost:3996/public/tests/test.html?__token=k8l88m:895
      at http://localhost:3996/public/tests/test.html?__token=k8l88m:1024
      at process (http://localhost:3996/public/tests/test.html?__token=k8l88m:583)
      at begin (http://localhost:3996/public/tests/test.html?__token=k8l88m:628)
      at http://localhost:3996/public/tests/test.html?__token=k8l88m:644
EN

回答 2

Stack Overflow用户

发布于 2015-06-27 02:00:19

看起来您是从file:// protocol加载的,对吗?如果是这样,这可能就是您的问题所在。

票数 0
EN

Stack Overflow用户

发布于 2015-06-27 05:07:08

我找到了我在代码中遗漏的地方。

main.js

代码语言:javascript
复制
import $ from 'jquery';
import _ from 'lodash';
import stache from 'can/view/stache/';
import can from 'can';
import 'components/route/';
import 'less/trinity.less!';

我没有在里面导入can/view/stache/system。要在can.stache中使用系统插件,我需要将特定文件导入到主javascript文件中。

因此,该文件应该是

代码语言:javascript
复制
import $ from 'jquery';
import _ from 'lodash';
import stache from 'can/view/stache/';
import 'can/view/stache/system';   // this is the added line
import can from 'can';
import 'components/route/';
import 'less/trinity.less!';
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31079318

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档